尝试将文件导出为PDF但出现错误,找不到命名参数。

huangapple go评论234阅读模式
英文:

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"

huangapple
  • 本文由 发表于 2023年8月5日 02:30:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76838401.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定