Macro throwing error

Programming and macros
User avatar
AlexLachance
Posts: 1982
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2134
x 1844

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 863 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 32 times
User avatar
AlexB
Posts: 434
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 21
x 240
x 383

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: 1819
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 13
x 2003
x 1677
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: 1982
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2134
x 1844

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: 30
Joined: Tue Aug 10, 2021 2:40 am
Answers: 2
x 42
x 61

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: 1982
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2134
x 1844

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: 249
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 11
x 19
x 440

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: 1819
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 13
x 2003
x 1677
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: 434
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 21
x 240
x 383

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 21 times
User avatar
AlexLachance
Posts: 1982
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2134
x 1844

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