Showing posts with label Run a Macro from Different Workbook. Show all posts
Showing posts with label Run a Macro from Different Workbook. Show all posts

Sunday, March 02, 2008

Run a Macro from Different Workbook

Execute a macro in a different workbook

Runs a macro or calls a function. This can be used to run a macro written in Visual Basic or the Microsoft Excel macro language, or to run a function in a DLL or XLL.

Sub Run_Macro_In_Different_WorkBook()

Application.Run "'C:\CanBeDeleted.xlsx.xlsm'!AnotherWrkBook_Macro"

End Sub


Runs a macro or calls a function. This can be used to run a macro written in Visual Basic or the Microsoft Excel macro language, or to run a function in a DLL or XLL.

Sub Run_Macro_In_Different_WorkBook_With_Arguments()

On Error GoTo Err_Trap

Application.Run "'C:\CanBeDeleted.xlsx.xlsm'!Function_Two_Args", "Argument 1", "Argument 2"

Err_Trap:
If Err <> 0 Then
Debug.Print Err.Number & Err.Description

End If


End Sub

The above code passes arguments to a macro in another workbook

The following errors need to be handled for forward compatibility of your macro

450 - Wrong number of arguments or invalid property assignment

449 - Argument not optional
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.