Code to run macros

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all, I don't know if it's the right nwgp, but I hope someone could help me ...
I've got a problem writing a code in a file (A) tha
runs macros in other files (in my example, I open file B that contains
"MacroB" I want to run, from file A)
I've written as follow, but I always have an "error-1004"
Where's my error

Sub InsertMacro(

Range("A2").Selec
Workbooks.Open Filename:="C:\...\B.xls
Sheets("Sheet1").Activat
Application.Run "MacroB
ActiveWorkbook.Sav
ActiveWindow.Clos

End Su

Thanks to all
 
P&M,

Try this

Application.Run "'C:\...\A.xls'!MacroB")


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Hi Bob
I tried
If I'm on the file B where I'm writing the code
Code open the file (A) that contains the macro (MacroB) I want to run
but it runs with effect on my file B, and not on the other A
How can I change

regard
 
This worked fine for me

Sub InsertMacro()
Range("A2").Select
Workbooks.Open Filename:="C:\myTest\Book1.xls"
Sheets("Sheet1").Activate
Application.Run "'Book1.xls'!Macro1"
ActiveWorkbook.Save
ActiveWindow.Close
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

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

Back
Top