通过 vba 将 excel 中的 word 文件另存为 pdf



所以我让项目打开 .dotx 并从 excel 文件中插入值并另存为.docx。 但我一辈子都不能把它当作.pdf保存。好吧,我可以,但是无法打开pdf。

Sub Cost_Statement()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim i As Integer
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
Application.ScreenUpdating = True
TemplateLocation = "C:Custom documentsCost_statement.dotx"
Set wrdDoc = wrdApp.Documents.Add(TemplateLocation, False, , False)
On Error GoTo NextNumber
cellno = "Main!C19"
FindText2 = "<<EXCELCOST>>"
ReplacementText2 = Range(cellno).Value
wrdDoc.Content.Find.Execute FindText2, ReplaceWith:=ReplacementText2, Replace:=wdReplaceAll
cellno = "Main!C20"
FindText3 = "<<EXCELDEST>>"
ReplacementText3 = Range(cellno).Value
wrdDoc.Content.Find.Execute FindText3, ReplaceWith:=ReplacementText3, Replace:=wdReplaceAll
NextNumber:
FileAddress = Range("Main!C21").Text
FileAddress = "C:Cost Statement pdfs" & FileAddress & ".docx"
With wrdDoc
.SaveAs (FileAddress)
.Close
End With
wrdApp.Quit
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub

任何帮助将不胜感激。

你试过这种方式吗?

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:PathPDF.pdf"

另请注意

FileAddress = Range("Main!C21").Text
FileAddress = "C:Cost Statement pdfs" & FileAddress & ".docx"

FileAddress = "C:Cost Statement pdfs" & FileAddress & ".docx"

相关内容

  • 没有找到相关文章

最新更新