Call Macro in Other Workbook

  • Thread starter Thread starter cogent
  • Start date Start date
C

cogent

Hello

If I am running a macro in ThisWorkbook, MyFile.xls, and I want to Call a
subroutine in Personal.xls, how can I do that? What is the syntax? Let's
assume the name of the procedure I want to call from Personal.xls is PMacro.

Sub Call_PMacro

???

End Sub

Thank you!
 
The simplest way is to use the Application.Run method. E.g.,

Application.Run "MyFile.xls!PMacro"


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Hi cogent

Use Application.run to call a macro in a other open workbook
Some notes on this from Chip Pearson

Application.Run "Book1.xls!MacroName"

Or, if the book name contains spaces, (watch the quotes)

Application.Run "'Book One.xls'!MacroName"
 
See your bubble thread for a possible solution to your previous problem.
 
What if I need to pass values to the PMacro? or Example the routine is
PMacro(datum1, Datum2).

Will the quotes allow that I pass values to PMacro?

W
 
If the procedure returns a value, use syntax like

Result = Application.Run ("'MyFile.xls'!PMacro", arg1, arg2)

If the procedure doesn't return a value, use
Application.Run "'MyFile.xls'!PMacro", arg1, arg2


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Thank you.

W
Chip Pearson said:
If the procedure returns a value, use syntax like

Result = Application.Run ("'MyFile.xls'!PMacro", arg1, arg2)

If the procedure doesn't return a value, use
Application.Run "'MyFile.xls'!PMacro", arg1, arg2


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

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