【发布时间】:2019-05-27 23:37:38
【问题描述】:
当我尝试将工作表导出为 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 版本较新。 有人知道解决方法或解决方法吗?
【问题讨论】: