objWorkbook.ExportAsFixedFormat Type:=xlTypePDF, filename:= _ strPDFPath & objFile.Name & ".pdf", Quality:= _ xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=False 无效的调用参数过程
时间: 2024-02-14 17:19:14 浏览: 137
这个错误通常是由于 Excel 库的版本不兼容所引起的。请尝试将代码中的导出语句修改为以下代码:
```vb
objWorkbook.ExportAsFixedFormat _
Type:=0, _
filename:=strPDFPath & objFile.Name & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
```
这段代码中的 Type 参数将 PDF 格式的值设置为 0,因为在一些 Excel 库版本中,xlTypePDF 常量可能不可用。请注意,以上代码中的 Type 参数是必需的,因为它确定了要导出的文件类型。如果导出的文件类型不正确,会导致“无效的调用参数过程”错误。另外,请确保您已经将代码中的文件夹路径和PDF输出路径修改为您实际使用的路径。
相关问题
objWorkbook.ExportAsFixedFormat _ Type:=0, _ filename:=strPDFPath & objFile.Name & ".pdf", _ Quality:=xlQualityStandard, _ IncludeDocProperties:=True, _ IgnorePrintAreas:=False, _ OpenAfterPublish:=False无效的调用过程货参数
如果您仍然遇到“无效的调用过程或参数”错误,可能是因为您的 Excel 库版本不支持 ExportAsFixedFormat 方法。在这种情况下,您可以尝试使用 Microsoft Print to PDF 打印机来将 Excel 文件转换为 PDF 文件。以下是示例代码:
```vb
Sub BatchConvertExcelToPDF()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim objExcel As Object
Dim objWorkbook As Object
Dim objPDFPrinter As Object
Dim strFolderPath As String
Dim strPDFPath As String
Dim intCounter As Integer
' 设置文件夹路径和PDF输出路径
strFolderPath = Environ("UserProfile") & "\Desktop\1\"
strPDFPath = Environ("UserProfile") & "\Desktop\PDF\"
' 创建文件系统对象
Set objFSO = CreateObject("Scripting.FileSystemObject")
' 获取文件夹对象
Set objFolder = objFSO.GetFolder(strFolderPath)
' 创建Excel对象
Set objExcel = CreateObject("Excel.Application")
' 创建PDF打印机对象
Set objPDFPrinter = CreateObject("WScript.Network").SetDefaultPrinter("Microsoft Print to PDF")
' 遍历文件夹中的所有Excel文件
For Each objFile In objFolder.Files
' 检查文件扩展名是否为.xlsx或.xls
If Right(objFile.Path, 5) = ".xlsx" Or Right(objFile.Path, 4) = ".xls" Then
' 打开工作簿
Set objWorkbook = objExcel.Workbooks.Open(objFile.Path)
' 更新标签控件的显示,并执行PDF转换
frmProgress.lblFileName.Caption = "正在处理:" & objFile.Name
DoEvents
intCounter = intCounter + 1
objWorkbook.PrintOut Copies:=1, ActivePrinter:="Microsoft Print to PDF", PrintToFile:= _
True, PrToFileName:=strPDFPath & objFile.Name & ".pdf"
' 关闭工作簿
objWorkbook.Close False
End If
Next objFile
' 释放Excel对象
objExcel.Quit
Set objExcel = Nothing
' 移除PDF打印机对象
Set objPDFPrinter = Nothing
' 显示转换完成的消息
MsgBox "已完成 " & intCounter & " 个文件的转换。"
End Sub
```
以上代码中,我们使用 PrintOut 方法将 Excel 文件打印到 Microsoft Print to PDF 打印机,然后使用 PrToFileName 参数将打印输出保存为 PDF 文件。在此过程中,我们没有使用 ExportAsFixedFormat 方法,因此不需要处理可能导致“无效的调用过程或参数”错误的问题。请注意,您需要将代码中的文件夹路径和 PDF 输出路径修改为您实际使用的路径。同时,需要在用户窗体中添加一个名为 lblFileName 的标签控件。
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ "C:\Users\UserName\Documents\FileName.pdf", Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False不提示正在发布
这是一个 VBA 代码,用于将当前活动的 Excel 工作表导出为 PDF 文件,保存在指定的文件路径下。其中,Quality 参数指定导出的 PDF 文件质量,IncludeDocProperties 参数指定是否包含文档属性,IgnorePrintAreas 参数指定是否忽略打印区域,OpenAfterPublish 参数指定是否在导出后打开 PDF 文件。如果设置为 False,则不会提示正在发布。
阅读全文
相关推荐
















