locked
VBA Fomat Date Help RRS feed

  • Question

  • MSP 2016 Pro, I have a number of macros that create different PDF files "sorted and filtered" for the end user's specific needs that I generate throughout the week.  They work fine. My last line of each is tailored such as:

     DocumentExport FileName:="C:\Users\Steve\XXX Program\Detail XYZ Near Due 30 Days.pdf"

    It create the file named "Detail XYZ Near Due 30 Days.pdf".  Is there a way to have it add the current date run as the lead in the name.  So it would create it as "20161113 Detail XYZ Near Due 30 Days.pdf".  (YYYYMMDD)  So I would not have to go into the directory each time to add it to each file?

    Steve

       
    Sunday, November 13, 2016 11:16 PM

Answers

  • Steve,

    Okay, sorry. You're right, there is a little "glitch" in the code I sent. It should have been this. The FullName property gives the full path and all you want added to the date is the file Name property. But it sounds like you got something working anyway despite my evil plan to derail you ;-)

    John

    Sub savewithdate()
    Dim NamPref As String
    NamPref = Year(ActiveProject.CurrentDate) & Month(ActiveProject.CurrentDate) _
        & Day(ActiveProject.CurrentDate) & ActiveProject.Name
    DocumentExport FileName:="C:\Users\Steve\XXX Program\" & NamPref, FileType:=pjPDF
    End Sub

    • Marked as answer by Mrcvn Monday, November 14, 2016 2:46 PM
    Monday, November 14, 2016 2:34 PM

All replies

  • Mrcvn,

    Sure, try this code.

    Sub savewithdate()
    Dim NamPref As String
    NamPref = Year(ActiveProject.CurrentDate) & Month(ActiveProject.CurrentDate) _
        & Day(ActiveProject.CurrentDate) & ActiveProject.FullName
    DocumentExport FileName:="C:\Users\Steve\XXX Program\" & NamPref, FileType:=pjPDF
    End Sub

    John

    Monday, November 14, 2016 12:12 AM
  • John,

    Thanks for quick reply...  (I'm a PM, programming is not my area of expertise.)  It stopped working on the DocumentExport FileName line and does not continue on to create a PDF file.

    Locals field shows:

    Expression - NamPref

    Value - "20161113C:\Users\Steve\XXX Program\XYZ Program.mpp"

    Type - String

    Looking for the file title to be "20161113 Detail XYZ Near Due 30 Days" as a PDF. The macro lines setup/apply the View, Table, Group, and Filter needed for this display of Near Due (tasks within) 30 days. That part works fine.

    Steve

    Monday, November 14, 2016 3:43 AM
  • John,

    I received a suggestion that works within my macro. 

    Dim timestamp As String
       
        timestamp = Format$(Now(), "yyyymmdd") + " Detail XYZ Near Due 30 Days.pdf"

        DocumentExport FileName:="C:\Users\Steve\Desktop\XXX Program\" + timestamp

    Many thanks to you and the Forum for the aid!

    Steve

    Monday, November 14, 2016 12:53 PM
  • Steve,

    Okay, sorry. You're right, there is a little "glitch" in the code I sent. It should have been this. The FullName property gives the full path and all you want added to the date is the file Name property. But it sounds like you got something working anyway despite my evil plan to derail you ;-)

    John

    Sub savewithdate()
    Dim NamPref As String
    NamPref = Year(ActiveProject.CurrentDate) & Month(ActiveProject.CurrentDate) _
        & Day(ActiveProject.CurrentDate) & ActiveProject.Name
    DocumentExport FileName:="C:\Users\Steve\XXX Program\" & NamPref, FileType:=pjPDF
    End Sub

    • Marked as answer by Mrcvn Monday, November 14, 2016 2:46 PM
    Monday, November 14, 2016 2:34 PM