Hi All,
I wanted to have code that would Toggle the Gridlines in the Activewindow.
The following code works well for this:
[vba]Option Explicit
Sub Toggle_Gridlines_Activewindow()
ActiveWindow.DisplayGridlines = Not ActiveWindow.DisplayGridlines
End Sub[/vba]
I wanted to add in some error handling in case soemthing unexpected happened, as follows:
[vba]Option Explicit
Sub Toggle_Gridlines_Activewindow()
On Error GoTo error_handler:
ActiveWindow.DisplayGridlines = Not ActiveWindow.DisplayGridlines
error_handler:
MsgBox "Error occurred when toggling gridlines in the Active Window"
End Sub[/vba]
For some reason, even though there is no error occurring when toggling, the macro still passses through to the error_handler i.e. the Msgbox is always displaye even though the toggle works without error. Could anyone please clarify what I am doing incorrectly above?
regards,