Re-POST: How to close forms opened from other workbooks...?

A

Andrew

Take It, It Can't be done..?
Thanx anyway.
| From: "Andrew" <NoToSPAM@home>
| Subject: How to close forms opened from other workbooks...?
| Date: Sun 12 June 2005 20:22
|
| I have a form that is loaded(show) from Personal.xls.
| Other workbooks can then be opened.
|
| Q. how is it possible to check if the form (Main.FRM) is open and close it
| or reference a listbox item if it is open.
|
| Is there a way of:
| If Userforms("Main") then
| ThisTextbox.text=Workbooks("Personal").Main.TextBox1.Text
| end if
|
| Thanks for any Help.
| Andrew
 
P

Peter T

Hi Andrew,

Not sure quite what you want to do but maybe something like this, with code
in two workbooks:

'' Book1, in a normal module
'' also in Book1, form "Userform1" and textbox "TextBox1"

Sub LoadForm()
UserForm1.Show vbModeless
UserForm1.Caption = ThisWorkbook.Name
End Sub

Function putText(s As String) As Boolean
Dim bRunning As Boolean
Dim uf As UserForm

If UserForms.Count Then
For Each uf In UserForms
If uf Is UserForm1 Then
bRunning = True
Exit For
End If
Next
End If

If s = "Quit" Then
If bRunning Then Unload UserForm1
Else
If bRunning = False Then LoadForm
UserForm1.TextBox1.Text = s
s = UserForm1.Caption
End If
putText = bRunning
End Function


'' in Book2, in a normal module
'' try Test1 & Test2 linked to buttons on a sheet in Book2

Sub RunForm(s As String)
Dim bWasRunning As Boolean
Dim sWBmame As String
sWBname = "Book1" ' change to suit
bWasRunning = Application.Run(sWBname & "!putText", s)
[a1] = "Form was already running : " & bWasRunning

End Sub

Sub Test1()
RunForm "Hi from " & ThisWorkbook.Name
End Sub
Sub Test2()
RunForm "Quit"
End Sub

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top