Jump to content

VBA Key Not Found Error


Robert Random

Recommended Posts

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

 

runtime error.jpg

 

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

Link to comment
Share on other sites

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.

 

screen_img.jpg

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...