View Single Post
 
Old 08-15-2017, 08:03 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If you just want to save with the data as the filename then that is easy enough. The following will warn if the folder is missing of the file exists.

Code:
Sub Print_to_PDF()
Dim strName As String
Dim fso As Object
Const strPath As String = "W:\Tenants\Rent\"
    Set fso = CreateObject("Scripting.FileSystemObject")
    If Not fso.FolderExists(strPath) Then
        MsgBox "The folder " & strPath & " does not exist."
        GoTo lbl_Exit
    End If
    strName = strPath & Format(Date, "yyyy-mm-dd") & ".pdf"
    If fso.FileExists(strName) Then
        If MsgBox("File " & strName & " exists." & vbCr & vbCr & _
                  "Do you want to overwrite", vbYesNo) = vbNo Then
            GoTo lbl_Exit
        End If
    End If

    ActiveDocument.ExportAsFixedFormat OutputFileName:=strName, _
                                       ExportFormat:=wdExportFormatPDF, _
                                       OpenAfterExport:=True, _
                                       OptimizeFor:=wdExportOptimizeForPrint, _
                                       Range:=wdExportAllDocument, _
                                       Item:=wdExportDocumentContent, _
                                       IncludeDocProps:=False, _
                                       KeepIRM:=True, _
                                       CreateBookmarks:=wdExportCreateNoBookmarks, _
                                       DocStructureTags:=True, _
                                       BitmapMissingFonts:=True, _
                                       UseISO19005_1:=False
lbl_Exit:
    Set fso = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote