VBA - Run macros over all sheets, not referring to workbook name

tlc53

Active Member
Joined
Jul 26, 2018
Messages
399
Hi,
I've finally got everything working how I need it to (thanks to the people on here!) and now I'm at the last hurdle.
From my Dashboard sheet, I then want to select each sheet and run the necessary macro. Once done, it takes me back to the Dashboard.
The problem with my code below, is that if refers to Workbook name 'Invoice Converter - Template'. I really need it not to, as the sheet will be renamed each month and this will stop the macro working.
How do I get around this/run the macros on each sheet? Thank you.

Code:
Sub ApplyAll()
'
' ApplyAll Macro
'


'
   Sheets("Monthly Data").Select
    Application.Run "'Invoice Converter - Template.xlsm'!CleanUp"
    Sheets("Cordis").Select
    Application.Run "'Invoice Converter - Template.xlsm'!ClientNarrative"
    Sheets("Hilton Banquets").Select
    Application.Run "'Invoice Converter - Template.xlsm'!ClientNarrative"
    Sheets("Hilton Cluster").Select
    Application.Run "'Invoice Converter - Template.xlsm'!ClientNarrative"
    Sheets("FourPoints").Select
    Application.Run "'Invoice Converter - Template.xlsm'!ClientNarrative"
    Sheets("Hilton Guest").Select
    Application.Run "'Invoice Converter - Template.xlsm'!ClientNarrative"
    Sheets("Pullman").Select
    Application.Run "'Invoice Converter - Template.xlsm'!ClientNarrative"
    Sheets("Sebel Manukau").Select
    Application.Run "'Invoice Converter - Template.xlsm'!ClientNarrative"
    Sheets("Stamford Plaza").Select
    Application.Run "'Invoice Converter - Template.xlsm'!ClientNarrative"
    ActiveWindow.ScrollWorkbookTabs Sheets:=-1
    Sheets("Dashboard").Select
    CommandButton1.Enabled = False
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi,
Is the workbook Template.xlsm, where you have the macro in place, the same from which you run it or another one? If that's the same then get a rid of all application run staff living after each select only the name of the macro you want to run. Check below code.

Code:
Sub ApplyAll()
Sheets("Monthly Data").Select
CleanUp
Sheets("Cordis").Select
ClientNarrative
Sheets("Hilton Banquets").Select
ClientNarrative
Sheets("Hilton Cluster").Select
ClientNarrative
Sheets("FourPoints").Select
ClientNarrative
Sheets("Hilton Guest").Select
ClientNarrative
Sheets("Pullman").Select
ClientNarrative
Sheets("Sebel Manukau").Select
ClientNarrative
Sheets("Stamford Plaza").Select
ClientNarrative
Sheets("Dashboard").Select
CommandButton1.Enabled = False
End sub
 
Upvote 0
Solution
The pleasure is mine :). Thanks for your feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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