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

139 views Asked by At

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
2

There are 2 answers

0
Eugene Astafiev On BEST ANSWER

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
2
Oscar  Sun On

How about this? Add the line after all

RecentFiles.Add Replace(ActiveDocument.FullName, ".docx", ".pdf")

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
    RecentFiles.Add Replace(ActiveDocument.FullName, ".docx", ".pdf")
End Sub

OR

Sub SaveAsPDF()

    ActiveDocument.SaveAs2 _
            Replace(ActiveDocument.FullName, ".docx", ".pdf"), wdFormatPDF, , , True
    RecentFiles.Add Replace(ActiveDocument.FullName, ".docx", ".pdf")
End Sub