【发布时间】:2015-02-20 16:41:24
【问题描述】:
我使用以下代码快速将活动 Word 文档转换为 PDF 并保存到桌面。它工作得很好,但是当我之后立即退出文档时,它总是询问我是否要进行更改,什么时候不应该进行。
有没有办法阻止它对文档进行这些不可见的更改,以便它立即退出(例如,如果它是在导出之前保存的)。
Sub PdfToDesktop()
'
'
Dim DeskTop As String
DeskTop = CreateObject("WScript.Shell").SpecialFolders("Desktop")
Dim fileNameOnly As String
Dim fileNameDot As Integer
fileNameDot = InStr(1, ActiveDocument.Name, ".")
fileNameOnly = Left(ActiveDocument.Name, fileNameDot - 1)
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
DeskTop & "\" & fileNameOnly & ".pdf", ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=True, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, _
IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _
wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
True, UseISO19005_1:=False
ChangeFileOpenDirectory DeskTop
End Sub
【问题讨论】:
-
如果您添加
ActiveDocument.Saved = True,则不会提示您保存更改(但请注意,如果您在运行导出宏之前进行了其他更改,那么如果您不保存,这些更改也可能会丢失关闭...)