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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I know it is, but is it definitely being executed?
 
Upvote 0
VoG
NamShortList is in a regular Module.

Originally I had
Code:
 Call NamShortList
line in here until a few months ago when users who were upgraded to Office 2010 started reporting issues that the worksheet was not longer working. Switching to
Code:
 Application.Run "'!Test.xlsm'!NamShortList"
took care of that issue.

Norie,

How can I tell if the EnableEvents is being executed?

Thanks
 
Upvote 0
In the code window press CTRL + G, type in

Application.EnableEvents=True

then see if the code triggers.
 
Upvote 0
VoG,

I did the Ctrl+G function, typed in the code that and now it works fine. Including the Application.Run "NamShortList" code.

I not sure what that did, but I'll take it.

VoG and Norie thank you both so much for your help. Your both a valuable asset to the Mr. Excel community.

Thanks Again,
-Alex
 
Upvote 0
Alex

Glad you got it working.:)

You should try and find out why it happened in the first place, perhaps it's avoidable.
 
Upvote 0
What happened was this. The first line of your event code disables events. When your code failed it happened with events turned off so they stayed off.
 
Upvote 0
No, because with events disabled your Worksheet_Change sub would not fire when you made a change to the worksheet.
 
Upvote 0
You can avoid this problem like this

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ExitNicely
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 "CreateData"
    'When changed, this macrco recreates the variance between TPM and the
    'Key Figure selected
    Case "$E$2"
        Application.Run "CalVariance"
    
    Case "$C$2"
        If Range("C2") = "Exception" Then Application.Run "CalVariance"
        Range("A4") = "Select Your Brand"

    Case "$C$4"
        Range("A4") = "Select Your Brand"
End Select
ExitNicely:
If Err <> 0 Then MsgBox "Error occurred: " & Err.Description, vbExclamation
Application.EnableEvents = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
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