Macro throwing error

Programming and macros
User avatar
AlexLachance
Posts: 2184
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2364
x 2013

Macro throwing error

Unread post 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 1605 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.
Attachments
NoteLevelSel.swp
(108.5 KiB) Downloaded 82 times
User avatar
AlexB
Posts: 501
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 268
x 445

Re: Macro throwing error

Unread post 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?
User avatar
SPerman
Posts: 2055
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 14
x 2225
x 1876
Contact:

Re: Macro throwing error

Unread post 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)
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
User avatar
AlexLachance
Posts: 2184
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2364
x 2013

Re: Macro throwing error

Unread post 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"
User avatar
Stefan Sterk
Posts: 37
Joined: Tue Aug 10, 2021 2:40 am
Answers: 3
x 51
x 77

Re: Macro throwing error

Unread post by Stefan Sterk »

I believe the selected component is Ligthweight, which will throw an error when pulling the custom properties.
User avatar
AlexLachance
Posts: 2184
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2364
x 2013

Re: Macro throwing error

Unread post 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!
User avatar
josh
Posts: 295
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 16
x 22
x 508

Re: Macro throwing error

Unread post 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.
User avatar
SPerman
Posts: 2055
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 14
x 2225
x 1876
Contact:

Re: Macro throwing error

Unread post 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
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
User avatar
AlexB
Posts: 501
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 268
x 445

Re: Macro throwing error

Unread post 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.
Attachments
NoteLevelSel.swp
(108.5 KiB) Downloaded 60 times
User avatar
AlexLachance
Posts: 2184
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2364
x 2013

Re: Macro throwing error

Unread post 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.
Post Reply