Active Workbook Name To Call a Macro

alexaronson

Active Member
Joined
Sep 30, 2005
Messages
314
Hello and thank you for your help

I have the following code that calls a macro for me.

Code:
Application.Run "Test.xlsm'!NamShortList"

One of the problems I am runnign into is that my users are changing the file name. So I thought about changing the file name to a variable with the following code
Code:
Dim WbName As Variant
WbName = ActiveWorkbook.Name
I am trying to replace the Test.xlsm piece of the original code with WbName. However I can't seem to get the macro to fire off.

Any suggestions?
Thanks
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I may be missing something but can't you just use

Code:
Application.Run "NamShortList"
 
Upvote 0
VoG,

I tried that originally when I first built my sheet, but it would not work. Maybe because it in a Prive Sub Worksheet_Change(ByVal Target As Range) macro.
 
Upvote 0
I just tried it with NamShortList in a regular module. It fired when called from a WorkSheet_Change event.
 
Upvote 0
Hi Alex,

Code:
Application.Run "'" & Application.ActiveWorkbook.Name & "'!NamShortList"

The above code runs at my end, can you please share the error message?

Regards,
Kunal Shrivastava
 
Upvote 0
VoG,

It is still not working for me.

Here is my code in full. Maybe something will stand out.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False

Select Case Target.Address
    'Nam Changes triggers macro to create a list of brands for the nam
    Case "$A$2"
        Application.Run "!NamShortList"
        'Once the brand is selected, this macro creates the data to display
    Case "$A$4"
         Application.Run "Test.xlsm'!CreateData"
    'When changed, this macrco recreates the variance between TPM and the
    'Key Figure selected
    Case "$E$2"
        Application.Run "Test.xlsm'!CalVariance"
    
    Case "$C$2"
        If Range("C2") = "Exception" Then Application.Run "Test.xlsm'!CalVariance"
        Range("A4") = "Select Your Brand"

    Case "$C$4"
        Range("A4") = "Select Your Brand"
End Select
Application.EnableEvents = True

End Sub
 
Upvote 0
Is NamShortList in a regular module?

Does this work?

Code:
Call NamShortList
 
Upvote 0
Are you sure events are enabled?

They might have been disabled, then for whatever reason not re-enabled.

That's probably more likely to happen if you are branching off to different subs.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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