Wednesday, December 30, 2015

How to Run a Macro from Other Workbook

Here the example.

Macro in Book2:

1
2
3
Sub MacroBook2()
MsgBox "This macro from book2"
End Sub

Macro in Book1, from this macro we call MacroBook2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
Sub MacroBook1()

Dim DestWB As Excel.Workbook

Set DestWB = Workbooks.Open(ThisWorkbook.path & "\Book2.xlsm")

Application.Run "'" & DestWB.Name & "'!MacroBook2"

Set DestWB = Nothing

End Sub


Download File1 and File2 (Place both in same directory)















No comments :

Post a Comment