View Single Post
 
Old 11-07-2017, 04:40 AM
slaycock slaycock is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Sep 2013
Posts: 255
slaycock is on a distinguished road
Default

A further solution, which might be just as functional, is to just save the file with a suitable timestamp. The macro below should be called from whichever save function of word that you trap/redirect.

Code:
Sub save_doc_with_pdf_timestamp(doc As Document)
   
    Dim myFullName   As String
    Dim myFullNameTS   As String
    
    ' SaveAs2 changes the name of the current document
    ' therefore we need to preserve the current full name
    myFullName = doc.FullName
    myFullNameTS = replace(doc.FullName, ".", Format$(Now(), "-yyyy-mm-dd-hh-mm-ss."))
    ' Saveas2 fails if we don't use the correct file type
    ' change docx to doc if needed.
    myFullNameTS = replace(myFullNameTS, ".docx", ".pdf")
    doc.SaveAs2 filename:=myFullNameTS, FileFormat:=wdFormatPDF
    ' SAVE THE WORD DOCUMENT LAST TO REINSTATE THE FILE NAME.
    doc.SaveAs2 filename:=myFullName
        
End Sub
Reply With Quote