【发布时间】:2018-02-08 05:25:53
【问题描述】:
我正在使用一个 vba 代码,它将文件夹中的多个 word 文档转换为单个 pdf 文件。
问题是我无法将word文件另存为pdf。
下面是代码:
Sub convertword()
Dim Filename As String
Dim irow As Integer
Dim jsObj As Object
Dim NewFileName As String
Dim objWord As Object
Dim strDocName As String, strDocName1 As String, strDocName2 As String
Dim strMyPath As String
irow = 4
Do While Cells(irow, 2) <> Empty
Filename = Cells(irow, 2).Value
NewFileName = Cells(irow, 3).Value
Set objWord = CreateObject("word.Application")
objWord.Visible = True
objWord.Documents.Open Filename
'Document.SaveAs Filename, wdFormatPDF
'ActiveDocument.Visible = True
ActiveDocument.ExportAsFixedFormat OutputFileName:=NewFileName, ExportFormat:=wdExportFormatPDF
'ActiveDocument.Close
irow = irow + 1
Loop
End Sub
ActiveDocument.ExportAsFixedFormat OutputFileName:=NewFileName, ExportFormat:=wdExportFormatPDF 行给出错误“此命令不可用,因为没有打开文档”。
我可以打开文档,但无法将文档另存为 pdf。 提前谢谢!
【问题讨论】: