A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
HansV wrote:
Before you run a macro, the Visual Basic Editor checks the macro's code for syntax error. [....] Just remove that part from the macro.
Only if Option Explicit is set (see below). So the practical choices are:
- Remove or comment out the Option Explicit statement. Usually not really a good idea.
- Change Sheet32.Select to Sheets("Sheets32").Select, if that is what you really mean.
Sheet32 is an object name. Sheets("Sheet32") is the worksheet name that you see in the tabs at the bottom of the Excel window.
The worksheet named "Sheet32" might not be the worksheet object Sheet32.
I use object names when I want the flexibility of changing the worksheet name.
So, think about what ws.CodeName truly represents.
If it truly represents an object name and you want the option to delete or omit that worksheet, I think that #1 is the only practical option -- unless you want to use #If ... #End If to "comment" out the offending code manually, but optionally.
The following works without error, assuming there is no worksheet object Sheet123, because Option Explicit is commented out.
' Option Explicit (note the initial apostrophe on the left)
Sub testit()
Dim x As Variant
x = 1
Select Case x
Case 1:
MsgBox Range("a1").Address(external:=True)
Case Else:
MsgBox Sheets123.Range("a1").Address(external:=True)
End Select
End Sub
There should be no VBA error. But if you uncomment (reactivate) Option Explicit, VBA detects a compile-time (not runtime) error.