2
我有這樣的代碼:自動化錯誤 - VBA(EXCEL)
Sub ChangeImportedBOQCodeName(importedName As String)
ActiveWorkbook.VBProject.VBComponents(ActiveSheet.CodeName).Name = "BOQ_" & importedName
End Sub
即從
Private Sub cmdOK_Click()
Dim TargetName As String
TargetName = cbxSheets.Text
Set TargetSheet = TargetWB.Sheets(TargetName)
TargetSheet.Copy After:=SourceWB.Sheets(SourceSheet.Index)
ChangeImportedBOQCodeName ActiveSheet.CodeName
' Close the User Form
Unload Me
' Inform User on Successful BOQ Import
MsgBox "The selected BOQ was successfully imported to the Analysis", vbInformation, "Import Successful"
' Ask User to generate codes automatically
Dim msgTxt As String
msgTxt = "Generate codes in the imported BOQ, automatically ?" & vbNewLine & vbNewLine & _
"(The proccess may take a while depending on the System specs and BOQ layout and size)"
If MsgBox(msgTxt, vbYesNo, "Auto Code BOQ") = vbYes Then
CheckImportedBOQ ActiveSheet
Else
MsgBox "Auto code genrate was aborted", vbInformation, "Aborted"
End If
End Sub
稱爲但是我得到這個錯誤:
Run-time error '-2147417848 (80010108)' Automation error The object invoked has disconnected from its client
並且excel突然退出。
問題是,這個錯誤之前從未發生,代碼工作得很好。
我也試過評論ChangeImportedBOQCodeName ActiveSheet.CodeName
這一行和代碼的作品。
它的工作,非常感謝。 – Tima
@Tima歡迎:) –