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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
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
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,214,385
Messages
6,119,210
Members
448,874
Latest member
b1step2far

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