Call function from other workbook.

J

Joe

Hi all,

I have two files 1.xls and 2.xls.

1.xls is open
2..xls is not open.

from 1.xls I have to display a form which is in 2.xls

My code is...

'******************************************
' Code in 1.xls

Function WorkbookOpen(ByVal WorkBookName As String) As Boolean
' returns TRUE if the workbook is open

WorkbookOpen = False
On Error GoTo WorkBookNotOpen
If Len(Application.Workbooks(WorkBookName).Name) > 0 Then
WorkbookOpen = True
Exit Function
End If

WorkBookNotOpen:
End Function

'***************************************************

Private Sub Go_Click()
'to initiate the second form

Dim NewFile As String

NewFile = "2.XLS"

If Not WorkbookOpen(NewFile) Then
Workbooks.Open NewFile
End If

' I WANT TO ADD CODE FOR CALLING THE FUNCTION STARTFORM()
' WHICH IN TURN WILL MAKE THE FORM TO BE SHOWN.
' STARTFORM() is in Model1 of 2.xls

Me.Hide
ThisWorkbook.Close False

End Sub


'******************************************


I tried to google, but I get confused. Could not find any specific
result...
I would like to know how I can call the function "STARTFORM()" which
is in the Module1 of 2.XLS.

Thanks a lot.....

Regards
Joe
 
B

Bob Phillips

Private Sub Go_Click()
'to initiate the second form

Dim NewFile As String

NewFile = "2.XLS"

If Not WorkbookOpen(NewFile) Then
Workbooks.Open NewFile
End If

Application.Run "2.xls!StartForm"

Me.Hide
ThisWorkbook.Close False

End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

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