【发布时间】:2018-07-06 07:09:20
【问题描述】:
当 Catia 尝试在选定的 Excel 工作表中写入值时,我收到了自动化错误。这有点令人困惑,因为在第一次尝试代码时没有错误,并且值在 Excel 表中。
我没有更改代码,但在第二次尝试时我得到了:
Run-time error '-2147417846 (8001010a)': Automation error
"The Message filter indicated that the application is busy."
在线:Set MyXL = GetObject(FPath)
Sub CATMain()
FPath = CATIA.FileSelectionBox("Select the Excel file you wish to put the value in", "*.xlsx", CatFileSelectionModeOpen)
If FPath = "" Then
Exit Sub
End If
Set xlApp = CreateObject("Excel.Application")
Set MyXL = GetObject(, "Excel.Application")
Set MyXL = GetObject(FPath)
MyXL.Application.Visible = True
MyXL.Parent.Windows(1).Visible = True
Dim oSelection As Selection
Set oSelection = CATIA.ActiveDocument.Selection
Dim oProduct As AnyObject
On Error Resume Next
Set oProduct = oSelection.FindObject("CATIAProduct")
If (Err.Number <> 0) Then
MsgBox "No selected product"
Else
On Error GoTo 0
Dim oInertia As AnyObject
Set oInertia = oProduct.GetTechnologicalObject("Inertia")
Dim dMass As Double
dMass = oInertia.Mass
Dim dDen As Double
dDen = oInertia.Density
MsgBox oProduct.Name & ": Masse = " & CStr(dMass) & " KG" & ": Dichte = " & (CStr(dDen) / 1000) & " "
MyXL.Application.Cells(1, 1).Value = "Masse"
MyXL.Application.Cells(2, 1).Value = dMass
MyXL.Application.Cells(1, 2).Value = "Dichte"
MyXL.Application.Cells(2, 2).Value = "dDen"
MsgBox "Werte wurden in Excel eingetragen"
End If
End Sub
【问题讨论】:
-
您能否分享“自动化错误”的完整错误消息?
-
FPath 是否有 Dim 语句?
-
运行时错误'-2147417846 (8001010a)':自动化错误,消息过滤器指示应用程序正忙
-
不,它没有暗淡@Solar Mike
-
我认为问题是当我第一次使用宏时,它打开了 Excel,但它不再关闭它,我该如何关闭它?
标签: excel vba automation catia