Run excel macro on one xls from another xls

G

Guest

I need to call a macro Macro1 written in A.xls from another macro Macro2
written in b.xls.

The file name "a.xls" is actually stored in column A on of b.xls, thus is in
a variable. Macro name Macro1 is defined and static.
 
G

Guest

Hi Kishore Shenoi,

In Macro2 use the command
Application.Run "A.xls!Macro1"

If the name of the macro (say Macro1) is stored on the active sheet in
B.xls, say in A1, you can read it into a VBA variable (say MName), append the
workbook name and then run it like this:

MName = Range("A1")
MName = "A.xls!" & MName
Application.Run MName

Hope this helps
 
M

Mike Fogleman

Application.Run ("'A.xls'!Macro1")

Sorry, I left out the first single quote.

Mike F
 
M

Mike Fogleman

Here is an example from one of my workbooks if the workbook with the macro
to run is not open, but is in the same folder and is password protected to
open it...

Dim cdir As String
Dim wb As Workbook

For Each wb In Workbooks
If wb.name = "NCP C4-1 Tracking.xls" Then
MsgBox ("NCP C4-1 Tracking.xls is already open.")
Exit Sub
End If
Next wb
cdir = ActiveWorkbook.Path
Workbooks.Open cdir & "\NCP C4-1 Tracking.xls", password:="NCP"
Application.Run ("'NCP C4-1 Tracking.xls'!RunUpdate")

Substitute your workbook name, macro name, and password as needed.

Mike F
 

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