PDA

View Full Version : Saving a file with the current date



netwerkz
01-10-2017, 10:47 AM
year_Month = Format(DateAdd("m", 1, Date), "yyyy Mmm")
Yr = Format(Application.WorksheetFunction.EoMonth(Date, 1), "yyyy")
Mnth = Format(Application.WorksheetFunction.EoMonth(Date, 1), "mmm")
'
' This is the save portion
'
ChDir "D:\Daily Documents\Projects\Website\"
ActiveWorkbook.SaveAs Filename:= _
"D:\Daily Documents\Projects\Website\" & Yr & "\" & year_Month & "\" & year_Month & " - " & "Diversified Bidsheet.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"D:\Daily Documents\Projects\Website\" & Yr & "\" & year_Month & "\" & year_Month & " - " & "Diversified Bidsheet.pdf"





I copied the framework of a former project and tried to edit it for a new project.

I open a file sent to me in M$ Outlook, edit it (reformatting the aesthetics), and save it in a particular location in (2) two types: "*.xlsx" & "*.pdf". Once I have ran my script and saved it, I eventually want to auto upload to a WordPress editor on my web-host's site.

I want to save the file with the current date in "##" (two-digit) format. So, when I run the file for today, it would save it as

"D:\Daily Documents\Projects\Website\2017\2017 Jan\2017 Jan 10 - Diversified Bidsheet.pdf"

What am I missing?

SamT
01-11-2017, 09:51 AM
See if this works



NewDate = Format(DateAdd("m", 1, Date)
YMD = Format(NewDate), "yyyy Mmm dd") & " - "
YM = Format(NewDate, "yyyy Mmm") & "\"
Y= Format(NewDate, "yyyy") & "\"

' This is the save portion
ActiveWorkbook.SaveAs Filename:= _
"D:\Daily Documents\Projects\Website\" & Y & YM & YMD & "Diversified Bidsheet.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"D:\Daily Documents\Projects\Website\" & Y & YM & YMD & "Diversified Bidsheet.pdf"