Consulting

Results 1 to 2 of 2

Thread: Saving a file with the current date

  1. #1
    VBAX Regular
    Joined
    Nov 2014
    Location
    Idaho
    Posts
    36
    Location

    Red face Saving a file with the current date

        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?

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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"
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •