Reading File Name in VB Macro that contains today's date
Thanks for the great answers. Reading the file works fine. But now in the
macro there is a point where I switch windows and then switch back again.
The switching back isn't working. Here is the Hard coded line commented out
and the calculated name that isn't working. What am I doing wrong?
'Windows("sales_daily_2008-11-10.csv").Activate
Windows(DailySalesName).Activate
"Dave Peterson" wrote:
VBA has its own Format() function that you can use:
dim myFileName as string
myfilename = "sales_" & format(date-1,"yyyy-mm-dd") & ".csv"
If you need to watch out for Mondays (or weekends), maybe you can modify
something like this:
Dim myFileName As String
Dim myAdj As Long
Select Case Weekday(Date)
Case Is = vbSunday: myAdj = -2
Case Is = vbMonday: myAdj = -3
Case Else
myAdj = -1
End Select
myFileName = "sales_" & Format(Date + myAdj, "yyyy-mm-dd") & ".csv "
MsgBox myFileName
dhstein wrote:
Is it possible to have a macro that opens a file that has a date in it.
Specifically I need to open yesterday's file that would be called
Sales_2008_11-10.csv. Obviously this name changes every day. Thanks for any
help.
David
--
Dave Peterson
|