更新时间:2023-02-12 21:54:29
如果要保存PDF,则需要使用适当的保存格式 - 这不是wdFormatXMLDocument!尝试:
If you want to save a PDF, then you need to use the appropriate save format - which isn't wdFormatXMLDocument! Try:
Sub ConvertToPDF()
Dim file As Variant, wdDoc As Document
file = Dir("C:\Text" & "*.txt") 'txt path
Do While (file <> "")
Set wdDoc = Documents.Open(FileName:="C:\Text" & file, ReadOnly:=True, _
AddToRecentFiles:=False, Format:=wdOpenFormatAuto, Visible:=False)
wdDoc.SaveAs2 FileName:="C:\Text2" & Replace(file, ".txt", ".pdf"), _
FileFormat:=wdFormatPDF, AddToRecentFiles:=False
wdDoc.Close False
file = Dir
Loop
End Sub