Robert Random Posted November 25, 2016 Share Posted November 25, 2016 Hi. I pasted the following code from a help file, into a new .dvb file and ran it. I used to work fine. Currently it gives me an error (shown below). It used to work fine previously. I reinstalled ACAD and the VBA enabler. Still same. Not sure what to do. Thanks in advance for any helpful advice. ~Robert Sub RemoveMyLayer() On Error Resume Next '' Get the layer "MyLayer" from the Layers collection Dim ABCLayer As AcadLayer Set ABCLayer = ThisDrawing.Layers.Item("MyLayer") '' Check for an error, if no error occurs the layer exists If Err = 0 Then '' Delete the layer ABCLayer.Delete '' Clear the current error Err.Clear '' Get the layer again if it is found the layer could not be removed Set ABCLayer = ThisDrawing.Layers.Item("MyLayer") '' Check for error, if an error is encountered the layer was removed If Err <> 0 Then ThisDrawing.Utility.prompt "'MyLayer' was removed" Else ThisDrawing.Utility.prompt "'MyLayer' could not be removed" End If Else ThisDrawing.Utility.prompt "'MyLayer' does not exist" End If End Sub Quote Link to comment Share on other sites More sharing options...
Dadgad Posted November 25, 2016 Share Posted November 25, 2016 Welcome to CADTutor Robert. Did you try the DEBUG option? Quote Link to comment Share on other sites More sharing options...
maratovich Posted November 25, 2016 Share Posted November 25, 2016 Run the macro line by line, using the F8 Quote Link to comment Share on other sites More sharing options...
Robert Random Posted November 26, 2016 Author Share Posted November 26, 2016 Thanks again. I really appreciate the help. When I run the code, line by line, it errors on the following. It's as if the statement "on error resume next" isn't accounted for. Quote Link to comment Share on other sites More sharing options...
maratovich Posted November 26, 2016 Share Posted November 26, 2016 1. Your drawing is not a layer named "MyLayer" 2. In the setting of the VBA editor put option: break on unhandled errors Quote Link to comment Share on other sites More sharing options...
Robert Random Posted November 26, 2016 Author Share Posted November 26, 2016 Ahh.. I think I may have it resolved. I selected the option on the dialog box... tools>options>general>error trapping> "Break on Unhandled Errors" It seems to be working with other code and the error isn't occurring... yet. Thanks again ~Robert Quote Link to comment Share on other sites More sharing options...
Robert Random Posted November 26, 2016 Author Share Posted November 26, 2016 Just saw the reply by maratovich. That's the resolve. Quote Link to comment Share on other sites More sharing options...
maratovich Posted November 26, 2016 Share Posted November 26, 2016 (edited) Good. In VBA - this setting default. Good luck! Edited November 26, 2016 by maratovich Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.