macro will not run if I rename my excel file

smerrick

Active Member
Joined
Feb 10, 2009
Messages
255
Little issue that has been bugging me and I was wondering if some guru out there could help with this. Each month I run a macro, part of which is: -

Range("A23").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Windows("02_Feb_O-Hs_09.xls").Activate
ActiveWindow.ScrollWorkbookTabs Position:=xlLast

The issue is that each month I rename the excel file, so where we have ("02_Feb_O-Hs_09.xls") the following month would be ("03_Mar_O-Hs_09.xls"), however when I run the macro it tells me it cannot find the original file name so I have to manually correct the above each time. Is there a way the vb code can be edited so that it reads the file name, so no matter what it is called , when I run the macro it will run?

Many Thanks for any help.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hi

You can call the name of the specific file the code resides in like:

Code:
ThisWorkbook.Name

So p[erhaps in your example:

Code:
Windows(ThisWorkbook.Name).Activate
 
Upvote 0

smerrick

Active Member
Joined
Feb 10, 2009
Messages
255
Thank you for that Richard, works a treat and saves me messing about with the change in vb code each and every month. Much appreciated.
 
Upvote 0

Forum statistics

Threads
1,191,320
Messages
5,985,964
Members
439,992
Latest member
NCWalker

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
Top