英文:
Tried to export file as PDF but had error Named argument not found
问题
我尝试从Excel宏中将Word文档导出为PDF,但当我尝试运行宏时,出现错误“未找到命名参数”,并突出显示“Type:=”。我不知道是否需要添加引用或其他内容,我缺少什么?
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim wdCell As Word.cell
With wdDoc
saveLocation = "https://orgindustrie-my.sharepoint.com/personal/different_person_org_com/Documents/folder/subfolder"
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=saveLocation & "/" & "File" & Range("G1").Value & ".pdf"
.Save
.Close
End With
我对VBA还相当陌生,所以不知道我做错了什么。非常感谢所有的帮助。
英文:
I tried to export a word document from an excel macro as PDF, but when I try to run the macro the error "Named argument not found" pops up and highlights "Type:=", I don't know if I need to add a reference or something, What am I missing?
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim wdCell As Word.cell
With wdDoc
saveLocation = "https://orgindustrie-my.sharepoint.com/personal/different_person_org_com/Documents/folder/subfolder"
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=saveLocation & "/" & "File" & Range("G1").Value & ".pdf"
.Save
.Close
End With
I am pretty new to vba, so I don't know what I'm doing wrong. Many thanks for all the help.
答案1
得分: 2
你混淆了Excel方法Workbook.ExportAsFixedFormat
和Word方法Document.ExportAsFixedFormat
。
对于Word:
参数
名称 必需/可选 数据类型 描述 OutputFileName 必需 字符串 新的PDF或XPS文件的路径和文件名。 ExportFormat 必需 WdExportFormat 指定PDF或XPS格式。
所以:
.ExportAsFixedFormat ExportFormat:=wdExportFormatPDF, _
OutputFileName:=saveLocation & "/" & "File" & Range("G1").Value & ".pdf"
英文:
You're conflating the Excel method Workbook.ExportAsFixedFormat
and the Word method Document.ExportAsFixedFormat
.
For Word:
> ## Parameters
> | Name | Required/Optional | Data Type | Description |
> | ---- | ----------------- | --------- | ----------- |
> | OutputFileName | Required | String | The path and file name of the new PDF or XPS file.|
> | ExportFormat | Required | WdExportFormat | Specifies either PDF or XPS format. |
So:
.ExportAsFixedFormat ExportFormat:=wdExportFormatPDF, _
OutputFileName:=saveLocation & "/" & "File" & Range("G1").Value & ".pdf"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论