Setting macro to save as current date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smkdvr588
    New Member
    • Mar 2010
    • 2

    Setting macro to save as current date

    Not sure if this is the place to find the answer to my need, so hopefully someone can help. I have created a micro enabled Word template and my wish is to have a command button on the document perform a save as and to close the template without changing the original file. My issue is that I want the button to save the document as the current date, but have not figured out how to string it. I am working in the VBA format of Microsoft 2007. Here is what I have so far, with {{{Current Date}}} being the current date when saved

    Thanks
    .

    Private Sub CommandButton1_ Click()
    '
    ' Saveandexit Macro
    '
    '
    ChangeFileOpenD irectory " Y:\Truck Check\Engine 1\"
    ActiveDocument. ExportAsFixedFo rmat OutputFileName: = _
    "K:\Truck Check\Engine 1\{{{Current Date}}}.pdf", ExportFormat:= _
    wdExportFormatP DF, OpenAfterExport :=false, OptimizeFor:= _
    wdExportOptimiz eForPrint, Range:=wdExport AllDocument, From:=1, To:=1, _
    Item:=wdExportD ocumentContent, IncludeDocProps :=False, KeepIRM:=True, _
    CreateBookmarks :=wdExportCreat eNoBookmarks, DocStructureTag s:=True, _
    BitmapMissingFo nts:=True, UseISO19005_1:= False
    '
    ' stopexit Macro
    '
    '
    ActiveDocument. Close
    End Sub
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Try:
    Code:
    ChangeFileOpenDirectory "Y:\Truck Check\Engine 1\"
    ActiveDocument.ExportAsFixedFormat OutputFileName:= _
    "Y:\Truck Check\Engine 1\" & Format(Date, "mmddyyyy") & ".pdf", ExportFormat:=wdExportFormatPDF, _
    OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, _
    Range:=wdExportAllDocument, From:=1, To:=1, Item:= _
    wdExportDocumentContent, IncludeDocProps:=False, KeepIRM:=True, CreateBookmarks:= _
    wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
    True, UseISO19005_1:=False

    Comment

    • smkdvr588
      New Member
      • Mar 2010
      • 2

      #3
      Thanks

      I had seen several post on other web sites, and had been trying to input the string to complete the date issue, but had no luck. Your string worked perfectly, just that it took me some time to understand the whole aspect of making it work, but was finally able to manipulate the problem I was having.

      Thanks very much, and the guys at the fire dept Thank you as well.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        You are quite welcome.

        Comment

        Working...