excel - 如何修复“类不支持自动化或不支持预期接口”
问题描述
当我尝试将工作表导出为 PDF 时,我的一个宏给了我错误“类不支持自动化或不支持预期的接口”。
我将我的 excel 库存文件从运行 Windows 7 的 MacBook 移动到运行 Windows 10 的 PC。我每天使用的宏都可以工作,除了一个包含将工作表导出为 PDF 的宏。我研究了这个错误,发现自从我从 Windows 7 迁移到 Windows 10 后,dll 文件可能存在问题,这是有道理的,因为同一个宏在我的 Windows 7 机器上运行了几个月。完整的错误是:“运行时错误'430':类不支持自动化或不支持预期的接口。” 我对 exe 和 dll 文件不是很有经验,所以我找不到“更新”它们的方法
Sub ExportPDFProforma()
Application.ScreenUpdating = False
Sheets("Sheet1").Select
Dim ExportName As String
If Range("B5").Value = "" Then
ExportName = "Test"
Else
ExportName = Range("B5").Value
End If
Sheets("Sheet1").Copy Before:=Sheets(1)
Sheets("Sheet1 (2)").Select
Sheets("Sheet1 (2)").Move After:=Sheets(5)
Sheets("Sheet1 (2)").Select
Sheets("Sheet1 (2)").Name = "Print Preview"
Range("A1:L49").Select
Range("L49").Activate
Selection.Copy
ActiveSheet.Paste
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Call PreviewFormatting
Dim Shp As Shape
For Each Shp In ActiveSheet.Shapes
If Not Shp.Type = msoPicture Then
Shp.Delete
End If
Next Shp
If Range("B4") = "x" Then
Call HideBlankRows(Range("F14:F23"), Range("D36:D45"))
Else
Call HideBlankRows(Range("F14:F23"), Range("D34:D43"))
End If
Worksheets("Print Preview").Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\...", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
Range("A1:B1").Select
Application.DisplayAlerts = False
Sheets("Print Preview").Delete
Application.DisplayAlerts = True
Sheets("Sheet1").Select
Application.ScreenUpdating = True
End Sub
错误行是:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\...",
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
由于 Windows 10 上的 VB 版本较新,它也可能只是某个地方的语法错误。有人知道修复它的方法或解决方法吗?
解决方案
尝试这样的事情。我看不到要分析的完整代码,所以看看我的,也许你会发现一些差异。
Option Explicit
Sub ExportPDF()
Dim PDFFile as String
PDFFile = “C:\someFolder\MyFile.PDF”
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFFile,
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=OpenPDFAfterCreating
End Sub
推荐阅读
- debugging - 如何在 IntelliJ 中调试在 Kubernetes pod 中运行的 Kotlin 应用程序?
- r - 在 R 中运行“devtools::build_vignettes()”时如何修复“系统命令错误”?
- php - 如何在 Laravel 5.8 中使用 IF 和 ELSE 检查 mysql 表 NULL 或 NOT?
- python - 为什么输出顺序是原样 - 我认为它必须是其他的?
- compiler-errors - 有人在 Jetson TX2 上编译过 Tensorflow_federated 吗?
- python - 无法在烧瓶应用程序中使用 os.system 命令从 Docker 获取输出
- java - Java中的ArrayList多态性
- php - 使用用户名/密码远程配置 PHP Xdebug?
- ios - 使用 PageViewController 上的下一步按钮
- javascript - 通过 node.js 访问 MusicKit API 时出现 401 错误