![]() |
Save As name
I need to save a file with the following parameters. "Location 8/12/08" The
"Location" will be a static value but the date needs to be the sunday for the previous week. Thanks |
Save As name
Greg,
You won't be able to include the slash character as part of your filename, so maybe use the underscore character. Sub test() Dim dtPreviousSunday As Date Dim i As Integer i = Application.WorksheetFunction.Weekday(Date) If i = 1 Then dtPreviousSunday = Date - 7 Else i = i - 1 dtPreviousSunday = Date - (i + 7) End If ThisWorkbook.SaveAs "Z:\TEMP\Location " & Format(dtPreviousSunday, "mm_dd_yy") End Sub -- Hope that helps. Vergel Adriano "Greg H." wrote: I need to save a file with the following parameters. "Location 8/12/08" The "Location" will be a static value but the date needs to be the sunday for the previous week. Thanks |
Save As name
Works perfectly, thanks so much!
"Vergel Adriano" wrote: Greg, You won't be able to include the slash character as part of your filename, so maybe use the underscore character. Sub test() Dim dtPreviousSunday As Date Dim i As Integer i = Application.WorksheetFunction.Weekday(Date) If i = 1 Then dtPreviousSunday = Date - 7 Else i = i - 1 dtPreviousSunday = Date - (i + 7) End If ThisWorkbook.SaveAs "Z:\TEMP\Location " & Format(dtPreviousSunday, "mm_dd_yy") End Sub -- Hope that helps. Vergel Adriano "Greg H." wrote: I need to save a file with the following parameters. "Location 8/12/08" The "Location" will be a static value but the date needs to be the sunday for the previous week. Thanks |
Save As name
i = Application.WorksheetFunction.Weekday(Date)
If i = 1 Then dtPreviousSunday = Date - 7 Else In Vba, another technique is to switch the week reference to the following day (ie Monday) dtPreviousSunday = Date - Weekday(Date, vbMonday) -- HTH :) Dana DeLouis "Greg H." wrote in message ... Works perfectly, thanks so much! "Vergel Adriano" wrote: Greg, You won't be able to include the slash character as part of your filename, so maybe use the underscore character. Sub test() Dim dtPreviousSunday As Date Dim i As Integer i = Application.WorksheetFunction.Weekday(Date) If i = 1 Then dtPreviousSunday = Date - 7 Else i = i - 1 dtPreviousSunday = Date - (i + 7) End If ThisWorkbook.SaveAs "Z:\TEMP\Location " & Format(dtPreviousSunday, "mm_dd_yy") End Sub -- Hope that helps. Vergel Adriano "Greg H." wrote: I need to save a file with the following parameters. "Location 8/12/08" The "Location" will be a static value but the date needs to be the sunday for the previous week. Thanks |
All times are GMT +1. The time now is 07:17 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com