Running a macro in another workbook

Yeoman.jeremy

Board Regular
Joined
Apr 4, 2011
Messages
90
Hi there.

I am trying to run a macro from another workboook using
Code:
Application.Run "C:\Users\owner\Desktop\Development\Quoting Statistics!RDB_Selection_Range_To_PDF"

But when i try this i get error message
Run time Error'1004':
Application-defined or object-defined error


Help would be much appreciated thanks
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
are trying to run RDB_Selection_Range_To_PDF macro
from "C:\Users\owner\Desktop\Development\Quoting Statistics!"?
If so just try this small modification, not sure if that is the reason

Application.Run "C:\Users\owner\Desktop\Development\'Quoting Statistics.xls'!RDB_Selection_Range_To_PDF"
 
Last edited:
Upvote 0
I have a similar problem, I think it's syntax related!. So I used;

Code:
ChDir "path"
Application.Run "Filename.xls!MacroName"
 
Upvote 0
If you're filename has a space in it then its advised to put it in single quotes.
Eg: 'File Name.xls'

see if it works..Let me know if it does..
Thanks
 
Upvote 0
I have tried al of these ideas, and none of them seem to work.
I end up with the Error
Runtime error '1004':
Application-defined error or object-defined error.

Although, It DOES open up the workbook. Is there maybe some syntax difference for the macro name?

The workbook i am opening with it is a macro enabled workbook, so it's a '.xlsm' file, not the '.xls"
 
Upvote 0
use .xlsm instead of .xls in syntax. Also change macro security level as low in the workbook where macro is existing.


Thanks

vimal
 
Upvote 0
You are most probably getting that error because the RDB_Selection_Range_To_PDF Macro is located in a Class/Workbook or Sheet module. try placing the Macro in a Standard module and use the Run Method again.

If moving the Macro to a standard module is difficult because other codes will need to be removed as well then you could make the Macro PUBLIC and call it via the GetObject Method .

So if , for example, the RDB_Selection_Range_To_PDF Macro is in the Workbook module you could run it like this after making it Public :


Code:
Sub Test()

    Dim oWb As Workbook
    
    Set oWb = GetObject _
    ("C:\Users\owner\Desktop\Development\Quoting Statistics.xlsm")
    
    Call oWb.RDB_Selection_Range_To_PDF

End Sub
 
Upvote 0
use .xlsm instead of .xls in syntax. Also change macro security level as low in the workbook where macro is existing.
Macro security is already at the lowest, and I was using .xlsm in the coding, thanks


You are most probably getting that error because the RDB_Selection_Range_To_PDF Macro is located in a Class/Workbook or Sheet module. try placing the Macro in a Standard module and use the Run Method again.

the macro is located in a standard module i assume, it's not placed in any of the 'Sheet1' or 'Workbook' sections.
Also, what do you mean by 'making it public'?


Is that when it says "Public sub RDB_Selection_Range_To_PDF()"?

would it need to be this anyway?
 
Upvote 0
Hi,

I have created a file called 'Quoting Statistics.xlsm'
with a macro in a standard module called 'RDB_Selection_Range_To_PDF'
with a msgbox.

I have the workbook in a trusted location so there is no issue with macro security when the workbook is opened. You may want to try that option.

I called it from another workbook using

Code:
Application.Run [COLOR=blue]"[/COLOR][COLOR=red]'[/COLOR]C:\Documents and Settings\My Name\My Documents\My Macros\Quoting Statistics.xlsm[COLOR=red]'[/COLOR]!RDB_Selection_Range_To_PDF[COLOR=blue]"[/COLOR]

and it displays my message box from the macro RDB_Selection_Range_To_PDF

Note the single/double quotes.
 
Upvote 0

Forum statistics

Threads
1,224,612
Messages
6,179,890
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top