Chris, change the code to:
If Weekday(Now, 2) = 1 Then
Date_1 = Now - 6
Else
Date_1 = Now - (Weekday(Now, 2) + 6)
End If
The previous code was returning a text value (the format command).
Regards,
Barrie
Barrie Davidson
Barrie,
The change you suggested makes it easy to set Date_2 as a variable. However...a new problem exists:
I used the Previous version of the code to take the DATE of the prior Monday (formatted as mm-dd-yy) and use it in the filename.
Here's code that worked, until I tried to get the "date_2" variable:
Sub Save_sheet()
Dim SheetName As String
SheetName = ActiveSheet.Name
Dim WorkbookName As String
' If Weekday(Now, 2) = 1 Then
' Date_1 = Now - 6
' Else
' Date_1 = Now - (Weekday(Now, 2) + 6)
' End If
Format Date_1, "mm-dd-yy"
If Weekday(Now, 2) = 1 Then
Date_1 = Format(Now - 6, "mm-dd-yy")
Else
Date_1 = Format(Now - (Weekday(Now, 2) + 6), "mm-dd-yy")
End If
WorkbookName = SheetName & " " & Date_1 & " " & "thru" & " " '& Date_2
ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\All Users\Desktop\Test\" & WorkbookName & ".xls "
Can you suggest how I might get a Date_2 variable to work there?
Thanks a whole bunch!
Barrie,
The change you suggested makes it easy to set Date_2 as a variable. However...a new problem exists:
I used the Previous version of the code to take the DATE of the prior Monday (formatted as mm-dd-yy) and use it in the filename.
Here's code that worked, until I tried to get the "date_2" variable:
Sub Save_sheet()
Dim SheetName As String
SheetName = ActiveSheet.Name
Dim WorkbookName As String
' If Weekday(Now, 2) = 1 Then
' Date_1 = Now - 6
' Else
' Date_1 = Now - (Weekday(Now, 2) + 6)
' End If
Format Date_1, "mm-dd-yy"
If Weekday(Now, 2) = 1 Then
Date_1 = Format(Now - 6, "mm-dd-yy")
Else
Date_1 = Format(Now - (Weekday(Now, 2) + 6), "mm-dd-yy")
End If
WorkbookName = SheetName & " " & Date_1 & " " & "thru" & " " '& Date_2
ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\All Users\Desktop\Test\" & WorkbookName & ".xls "
Can you suggest how I might get a Date_2 variable to work there?
Thanks a whole bunch!
Hey...whatd'ya know, I got it working.
I just wrote code to generate "date_2" the same way you helped me get "date_1". Works like a charm.
Thanks for your help, Barrie.