Date Sensistive File Names

jrnyman

Board Regular
Joined
Mar 10, 2002
Messages
105
I need a macro to open a file daily whose name depends on the date. The filename is formatted as "Filename DDMM" where "ThisFile 0103" would refer to the file for March 1st. Any suggesstion for how I can use this dynamic filename in a macro? For now I have the user enter the four digit code in a cell and pass a concatenated reference as the filename. I'd like something more automatic. Thanks.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi

Not to sure what you call your file but this code will parse the current date in the format you want to a string.

Dim strWbk As String
strWbk = "This File " & Format(Date, "ddmm")
 
Upvote 0
The filename is "Transactions DDMM", and I need to open it from within a shared folder. How can I combine the date string with the filename and the file's location for opening it? Thanks.
 
Upvote 0
Try

Sub OpenIt()
Dim strWbk As String
strWbk = "Transactions " & Format(Date, "ddmm") & ".xls"
Workbooks.Open Filename:="C:OzGrid" & strWbk
End Sub

Just change the path to suit.
 
Upvote 0
that worked perfectly. Can you help me with the syntax for activating the window named "Transactions DDMM.xls" where Transactions DDMM is the variable strWbk? I don't know how to start with the variable and end with text (your example has the opposite). Thanks.
 
Upvote 0
Certainly, no problem!Point to note here:

1. The Variable has now been declared at the Module level. This way it will retain it's value.


Dim strWbk As String

Sub OpenIt()
strWbk = "Transactions " & Format(Date, "ddmm") & ".xls"
Workbooks.Open Filename:="C:OzGrid" & strWbk
End Sub

Sub ActivateIt()
Windows(strWbk).Activate
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,407
Members
448,894
Latest member
spenstar

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