Macro Coding Help

Perrister

Board Regular
Joined
Nov 30, 2004
Messages
93
I have a macro that I run daily, after the macro runs I manually go and update what I do not how to code.

Effectively there is information in a cell of a workbook, Cell G2, always G2. The thing is each week the file name changes by week number and the week number comes from Excel weeknum(today(),1) function.

So this week is Daily Report Week 39.xslx and next week it will be Daily Report Week 40.xslx and so on.

I know how to point to a cell in a macro but do not know how to write so account foe the week num changing? How could that be done in macro code? Any ideas? is it even possible?

Thanks in advance.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Use this in VBA:
VBA Code:
Application.WorksheetFunction.WeekNum(Date, 1)
 
Upvote 0
So do i write like this " Workbooks.Open Filename:="C:\Users\me\OneDrive - mycompany.com\Desktop\2024MasterWeek39.xlsx how do I get that function in this code?

Thanks Again
 
Upvote 0
Like this:
VBA Code:
Dim fName as String
fName = "C:\Users\me\OneDrive - mycompany.com\Desktop\2024MasterWeek" & Application.WorksheetFunction.WeekNum(Date, 1) & ".xlsx"
Workbooks.Open Filename:= fName
 
Upvote 0
Solution
So elegant and easy but so not, thank you so much for your sharing your expertise and helping here, greatly appreciated. I am so embarrassed by my coding skills, but I keep learning and trying.
 
Upvote 0
You are welcome.
No need to be embarrassed! We all started out that way too!
:)
 
Upvote 0

Forum statistics

Threads
1,222,902
Messages
6,168,938
Members
452,227
Latest member
sam1121

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