Reputation: 21
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
Upvotes: 0
Views: 201
Reputation: 49405
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
Upvotes: 1
Reputation: 1479
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
Sub SaveAsPDF()
ActiveDocument.SaveAs2 _
Replace(ActiveDocument.FullName, ".docx", ".pdf"), wdFormatPDF, , , True
RecentFiles.Add Replace(ActiveDocument.FullName, ".docx", ".pdf")
End Sub
Upvotes: 1