Page 1 of 1

Macro throwing error

Posted: Tue Sep 12, 2023 4:15 pm
by AlexLachance
I have a macro which we use to select the level at which a note will grab the property and it's not working anymore, it throws an error 91, object variable not set.
image.png
image.png (31.04 KiB) Viewed 1434 times
Could anyone help me? I've attached the macro, I'm sure it's something silly.

Basically, we link a note to a part/assembly and then use the macro to select the desired level to pick the property from. When we try to select the desired level, the error appears.

Re: Macro throwing error

Posted: Tue Sep 12, 2023 4:26 pm
by AlexB
Are you able to give a list of steps that causes it to fail and show what line it breaks on by clicking Debug?

Re: Macro throwing error

Posted: Tue Sep 12, 2023 4:31 pm
by SPerman
My guess, is that your index is wrong here. (i.e. the value for NumSels doesn't match the allowed values. You told it to grab #3 when there are only 2.)

Select Case swSelMgr.GetSelectedObjectType3(NumSels, -1)

Re: Macro throwing error

Posted: Tue Sep 12, 2023 4:42 pm
by AlexLachance
AlexB wrote: Tue Sep 12, 2023 4:26 pm Are you able to give a list of steps that causes it to fail and show what line it breaks on by clicking Debug?
Selecting a note, clicking on the macro and trying to select the level from the pop-up window was throwing the error, but it isn't throwing an error as of right now... Seems like it was a case of "Restart the darned program"

Re: Macro throwing error

Posted: Wed Sep 13, 2023 6:03 am
by Stefan Sterk
I believe the selected component is Ligthweight, which will throw an error when pulling the custom properties.

Re: Macro throwing error

Posted: Wed Sep 13, 2023 7:45 am
by AlexLachance
Stefan Sterk wrote: Wed Sep 13, 2023 6:03 am I believe the selected component is Ligthweight, which will throw an error when pulling the custom properties.
I will validate the next time my collegue gets the error, thanks Stefan!

Re: Macro throwing error

Posted: Wed Sep 13, 2023 8:33 am
by josh
Hey, I think I recognize that form...

Yep, if it happens again, definitely hit "debug" and show which line gets highlighted. If we're lucky the VBA debugger will actually hightlight the problem line.

Re: Macro throwing error

Posted: Wed Sep 13, 2023 8:39 am
by SPerman
If you aren't familiar with the VBA debugger, you should be. It is easy to learn and will be invaluable in sorting these types of issues.

https://www.myonlinetraininghub.com/debugging-vba-code

Re: Macro throwing error

Posted: Wed Sep 13, 2023 8:43 am
by AlexB
@AlexLachance If you add this code to the location shown in the image, it should solve what @Stefan Sterk was talking about.
image.png

Code: Select all

Dim suppression As Integer
suppression = myComp.GetSuppression
If suppression = swComponentLightweight Then
    myComp.SetSuppression2 (swComponentFullyResolved)
End If
Alternatively, the updated SWP file is attached.

Re: Macro throwing error

Posted: Wed Sep 13, 2023 9:00 am
by AlexLachance
josh wrote: Wed Sep 13, 2023 8:33 am Hey, I think I recognize that form...

Yep, if it happens again, definitely hit "debug" and show which line gets highlighted. If we're lucky the VBA debugger will actually hightlight the problem line.
I think you were the one that developed it for us :P

I did hit it but I wasn't quite understanding what I was being presented with. I believe it was in this general area, at "first get overall document properties" that was getting highlighted.
image.png

Thanks @AlexB for the little tweak, will give it a go! If I get more macro errors, I will definetly try adding a screenshot of the debugger next time.