Macro will not run correctly if workbook's name is changed. What should I do?

nevers711

New Member
Joined
Oct 11, 2022
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hello everyone,

I created some codes that runs a macro. However, I noticed that if the users changes the Workbook's name, the macro will not run correctly. Below is partial of my codes. As you can see the name of the Excel file I have is "Annual Report.xlsm". What can I do to make it properly run no matter what workbook name is? Thank you!!

VBA Code:
 Application.Run "Annual Report.xlsm'!Step1_Macro"
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Best solution: hang the guilty by their eyelids and beat them until they blink. Make sure everyone else sees what happens when you mess around in network folders.:eek:

Really, this is not a coding problem and there's not much you can do in that regard. It's much bigger than that and I'd call it interference.
 
Upvote 0
VBA Code:
Application.Run "Annual Report.xlsm'!Step1_Macro"

What is the name of the workbook that contains the above line of code? Is it also "Annual Report.xlsm"?
 
Upvote 0
VBA Code:
Application.Run "Annual Report.xlsm'!Step1_Macro"

What is the name of the workbook that contains the above line of code? Is it also "Annual Report.xlsm"?
Hi rlv01, the workbook's name is "Annual Report.xlsm". I have several worksheets in this excel book though. Is this what you are asking? The worksheet's name is "Metrics", but I don't think it matters because the only error message I got is because somebody changed Annual Report.xlsm
 
Upvote 0
I mean that if everything is in "Annual Report.xlsm", then you should be able to replace

VBA Code:
Application.Run "Annual Report.xlsm'!Step1_Macro"

with

VBA Code:
Call Step1_Macro

or just

VBA Code:
Step1_Macro

or

VBA Code:
Application.Run "Step1_Macro"

or

VBA Code:
Application.Run  ThisWorkbook.Name & "!Step1_Macro"
 
Upvote 0
Solution

Forum statistics

Threads
1,214,834
Messages
6,121,877
Members
449,056
Latest member
ruhulaminappu

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