Home > Software engineering >  Cannot enter the excelVBA appear in the "mode"
Cannot enter the excelVBA appear in the "mode"

Time:09-18

Private Sub ComboBox2_Click ()
CopyTemp
Application. DisplayAlerts=False
ThisWorkbook. Worksheets (" sheet1 "). The Delete
ThisWorkbook. Worksheets (template "test"). The Name="sheet1"
Application. DisplayAlerts=True
End Sub

The Function CopyTemp ()
Dim MyPath As String, RepTemp As Workbook
MyPath=ThisWorkbook. Path
The Set RepTemp=Workbooks. Open (Filename:="d: \ 222. XLSM", ReadOnly:=True)
RepTemp. Sheets (" test "templates). Copy After:=ThisWorkbook. Sheets (ThisWorkbook. Sheets. Count)
RepTemp. Close False
End the Function

I think through this code 222. XLSM worksheet template "test" is copied to the current in the workbook, and replace the current worksheet sheet1, but run into "ThisWorkbook. Worksheets (" sheet1"). The Delete "in" cannot enter the interrupt mode ", the great god, please help solve

CodePudding user response:

All commented On the Error Resume Next statement, running in the VBA IDE,
The error and then click the debugging, the cursor will stop error in the statement,
Or
In doubt may have a logical error statements in advance to set breakpoints, run through the breakpoint interrupt,

At this point can be used in the immediate window
? The variable name
Or
? The function name () function parameter
Or
Process (parameters)
Auxiliary debugging,

CodePudding user response:

This is a limitation of the software! Should be no solution,

Just like your VBA code at runtime:
You can not add or delete: module (standard module, module, etc.), the user form;
You also can't add or delete: type definition, API declaration, a custom function/process,
And so on...
Because these are involved in "structure," in "run", is can't change of engineering structure,
  •  Tags:  
  • VBA
  • Related