我正在尝试将 Word 文档另存为 PDF,但出现错误框
“运行时错误 '-214747259 (80004005) 这不是有效的文件名。”
这是我的代码:
Option Explicit
Private Sub cmdSave_Click()
Dim equipName As String, equipError As String, fileDate As String, pdfName As String, filePath As String
filePath = "C:\"
equipName = Replace(Left(ActiveDocument.Tables(1).Cell(1, 2).Range.Text, _
Len(ActiveDocument.Tables(1).Cell(1, 2).Range.Text) - 1), "/", "-")
equipError = Left(ActiveDocument.Tables(1).Cell(2, 2).Range.Text, Len(ActiveDocument.Tables(1).Cell(2, 2).Range.Text) - 1)
fileDate = Replace(Date, "/", "")
pdfName = equipName & "_" & equipError & "_" & fileDate
ActiveDocument.ExportAsFixedFormat OutputFileName:=filePath & pdfName & ".pdf", _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
End Sub
将文件保存为 PDF 的代码是我从我 SaveAs-ing 记录的宏中获取的。实际的文件路径要长得多,但为了简单起见,我将其命名为“C:\”(这也不起作用)。