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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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,224,811
Messages
6,181,081
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