Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to call a workbook2 sub from workbook1 in EXCEL VBA?

Status
Not open for further replies.

vladk

Programmer
May 1, 2001
991
US
If it is possible then how?

Thanks
 
Vladk,
Yes it is possible. Define your sub as public in book2:
Public Sub msg()
MsgBox ("This is Book2")
End Sub

Then call it from your other workbook like this:
Public Sub test()
Call Workbooks("book2.xls").msg
End Sub

VBArt
 
VBArt;
Thank you very much for your responce. I will use your way in my workbooks.

I found alternative approach to do this. If you are interested in please take a look:

The following Sub procedure assumes that the workbook ExcelFile.xls contains a macro called "TestMacro."

Sub XLTest()
Dim XL as Object

Set XL = CreateObject("Excel.Application")

XL.Workbooks.Open "C:\My Documents\ExcelFile.xls"

' If there is more than one macro called TestMacro,
' the module name would be required as in
'
' XL.Run "Module1.TestMacro"
'
' to differentiate which routine is being called.
'
XL.Run "TestMacro"

End Sub

Thank you again

Vlad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top