vbams-wordexport-to-pdfrecent-file-list

Why doesn't my Word macro for saving as PDF show up in Recent Items?


MS Word Macro Save as Pdf not showing up in Recent Items

If I use the File Save as PDF the filename.pdf shows in the Recent Items.

If I use this macro to create the PDF the Filename.pdf doesn't show in the Recent Items list.

Sub SaveAsPDF()
'
' Silent SaveAsPDF Macro
'
    ActiveDocument.ExportAsFixedFormat OutputFileName:= _
        Replace(ActiveDocument.FullName, ".docx", ".pdf"), _
        ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
        wdExportOptimizeForPrint, Range:=wdExportAllDocument, Item:= _
        wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
        CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
        BitmapMissingFonts:=True, UseISO19005_1:=False
    ActiveDocument.PrintOut Copies:=1
End Sub

Solution

  • You can use the Application.RecentFiles property for adding your files to the history of recent files.

    Use the Add method to add a file to the RecentFiles collection. The following example adds the active document to the list of recently-used files.

    Sub SaveAsPDF()
    '
    ' Silent SaveAsPDF Macro
    '
        ActiveDocument.ExportAsFixedFormat OutputFileName:= _
            Replace(ActiveDocument.FullName, ".docx", ".pdf"), _
            ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
            wdExportOptimizeForPrint, Range:=wdExportAllDocument, Item:= _
            wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
            CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
            BitmapMissingFonts:=True, UseISO19005_1:=False
        ActiveDocument.PrintOut Copies:=1
        If ActiveDocument.Saved = True Then 
          RecentFiles.Add Document:=ActiveDocument.Name 
        End If
    End Sub