• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Run Macro based on file name

camdevl09

New Member
Right now, I have a template file with macros in it. One of the macros runs all the other macros. The problem I am having is it will not work if I change the name of the file. The current template file code looks like this...


Application.Run "'Dashboard Template.xlsm'!OriginalDataFill"

Application.Run "'Dashboard Template.xlsm'!CreateCashFlow"

Application.Run "'Dashboard Template.xlsm'!CreatePOFlow"

Application.Run "'Dashboard Template.xlsm'!CreateLookAheads"


When I change the name of the file from "Dashboard Template," the macro will not work anymore. I tried the code below, but got an error message...


Application.Run ActiveWorkbook.Name & "!OriginalDataFill"

Application.Run ActiveWorkbook.Name & "!CreateCashFlow"

Application.Run ActiveWorkbook.Name & "!CreatePOFlow"

Application.Run ActiveWorkbook.Name & "!CreateLookAheads"


I get this error message... Run-time error 1004: Cannot run the macro 'Dashboard Template Test.xls,!OriginalDataFill". The macro may not be available in this workbook or all macros may be disabled.


Any thoughts? Thanks in advance...
 
If the macro is stored in the file that is trying to run the macro, you should be able to just write:

[pre]
Code:
Call OriginalDataFill
Call CreateCashFlow
Call CreatePOFlow
Call CreateLookAheads
[/pre]
Also, just as an FYI, you will usually want to avoid using ActiveWorkbook as a reference. Using ThisWorkbook helps make sure the code is operating on the workbook you are thinking of, since users can have multiple workbooks open.
 
Back
Top