Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 使用word SaveAs FileFormat:=wdFormatPDF creates.docx的VBA宏_Excel_Pdf_Ms Word_Vba - Fatal编程技术网

Excel 使用word SaveAs FileFormat:=wdFormatPDF creates.docx的VBA宏

Excel 使用word SaveAs FileFormat:=wdFormatPDF creates.docx的VBA宏,excel,pdf,ms-word,vba,Excel,Pdf,Ms Word,Vba,这将生成一个.docx文件。你不应该给我一份PDF吗 编辑: 我将.SaveAs行修改为: wordTemplate = "c:\someTemplate.docx" Set objWord = CreateObject("Word.Application") objWord.Visible = True objWord.documents.Add Template:=wordTemplate, NewTemplate:=False, DocumentType:=0 '''here I ite

这将生成一个.docx文件。你不应该给我一份PDF吗

编辑: 我将.SaveAs行修改为:

wordTemplate = "c:\someTemplate.docx"
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.documents.Add Template:=wordTemplate, NewTemplate:=False, DocumentType:=0

'''here I iterate and do stuffs, and then:'''


With objWord.ActiveDocument
    .SaveAs Filename:=("somePath" & "aName"), FileFormat:=wdFormatPDF
    .Close
End With
With objWord
    .Quit
End With


但是两者都会生成一个无法呈现的.pdf文件。

您需要像这样使用
SaveAs2
方法(如果它工作正常):


您需要像这样使用
SaveAs2
方法(如果它工作正常):


你得到什么取决于你作为“aName”传递的内容。例如,如果包含.docx扩展名,您的PDF将具有无效的.docx扩展名


您使用的是SaveAs还是SaveAs2对此没有任何区别。

您得到的内容取决于您作为“aName”传递的内容。例如,如果包含.docx扩展名,您的PDF将具有无效的.docx扩展名


无论您是使用SaveAs还是SaveAs2,这都没有区别。

好吧,我的问题与语法有关:

这不起作用:

wordTemplate = "c:\someTemplate.docx"
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.documents.Add Template:=wordTemplate, NewTemplate:=False, DocumentType:=0

'''here I iterate and do stuffs, and then:'''


With objWord.ActiveDocument

    .SaveAs2 "C:\test\MyDoc.pdf", 17

    '.SaveAs Filename:=("c:\test\" & "test"), FileFormat:=wdFormatPDF
    .Close
End With
With objWord
    .Quit
End With
尽管如此:

.SaveAs Filename:=(Hoja1.Range("N6").Text & Hoja1.Range("A1") & ".pdf"), FileFormat:=wdFormatPDF
那么,问题是,在改变这一点之后

.SaveAs (Hoja1.Range("N6").Text & Hoja1.Range("A1") & ".pdf"), 17
在下一行中,我要求保存对原始文档的更改(这在以前很有效)。它迫使我明确放弃如下更改:

.Close
最终解决办法是:

.Close _
        SaveChanges:=wdDoNotSaveChanges

我的问题与语法有关:

这不起作用:

wordTemplate = "c:\someTemplate.docx"
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.documents.Add Template:=wordTemplate, NewTemplate:=False, DocumentType:=0

'''here I iterate and do stuffs, and then:'''


With objWord.ActiveDocument

    .SaveAs2 "C:\test\MyDoc.pdf", 17

    '.SaveAs Filename:=("c:\test\" & "test"), FileFormat:=wdFormatPDF
    .Close
End With
With objWord
    .Quit
End With
尽管如此:

.SaveAs Filename:=(Hoja1.Range("N6").Text & Hoja1.Range("A1") & ".pdf"), FileFormat:=wdFormatPDF
那么,问题是,在改变这一点之后

.SaveAs (Hoja1.Range("N6").Text & Hoja1.Range("A1") & ".pdf"), 17
在下一行中,我要求保存对原始文档的更改(这在以前很有效)。它迫使我明确放弃如下更改:

.Close
最终解决办法是:

.Close _
        SaveChanges:=wdDoNotSaveChanges

抱歉,将.pdf附加到文件名末尾会生成无法可视化的损坏的.pdf。抱歉,将.pdf附加到文件名末尾会生成无法可视化的损坏的.pdf。抱歉,将.pdf附加到文件名末尾会生成无法可视化的损坏的.pdf。抱歉,将.pdf附加到文件名的末尾会生成无法可视化的损坏的.pdf。