×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Error 91

Error 91

Error 91

(OP)
Hello,
I use macro to Close Secondary Window in a part file SW2005.
I found macro in this forum. Thanks. Works fine.

Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
SplitterPosition = Part.FeatureManagerSplitterPosition
If SplitterPosition = 1 Then
toggle = 0.5
Else: toggle = 1
End If
Part.FeatureManagerSplitterPosition = toggle
End Sub

But when I am not in a part file program tells me:
“Run-time error 91” “Object variable or With block variable not set”
Something wrong in sentence:
“SplitterPosition = Part.FeatureManagerSplitterPosition”

How can I fix it.
Thank you in advance.

RE: Error 91

Do you have a document open?  I just tried the code and it worked fine with a document open and give "Error 91" without one.

Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...

RE: Error 91

(OP)
Hello Evan,
After i close a document and push signed keybutton i get an error message.

RE: Error 91

Let me ask the question a different way:

If you open a document, then run the macro, does your feature tree window get split as expected?

The reason I ask is the Part.FeatureManagerSplitterPosition call requires an open document.

Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...

RE: Error 91

(OP)
Evan,
I start SW2005, open a document, work inside; program works fine.
I close the document (no opened documents) push keyboard
button and get message.

RE: Error 91

I don't seem to have that problem, but if I had to hazard a guess, I would say that for some reason, your macro is still running.  Try adding an "End" command right before the End Sub.

Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...

RE: Error 91

(OP)
Evan, I added End command, but it did not help.

RE: Error 91

Is the code above all you are using?  If not, please post all your code.

Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...

RE: Error 91

(OP)
Sub main()



Set swApp = CreateObject("SldWorks.Application")

Set Part = swApp.ActiveDoc



SplitterPosition = Part.FeatureManagerSplitterPosition



If SplitterPosition = 1 Then

    toggle = 0.5

    Else: toggle = 1

End If



Part.FeatureManagerSplitterPosition = toggle



End

End Sub


 

RE: Error 91

Unless the key you are hitting is F5 (run in VBA), I am not sure why your code runs again.   I cannot seem to duplicate the problem.

What version and SP of SW are you running?

Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...

RE: Error 91

(OP)
Evan,
The keybutton I signed is F10; SW2005 SP0.0
Thank you.

RE: Error 91

F10 shouldn't do anything.  I thought you might be hitting F5 (the run command in VBA).  What happens if you hit "s" or "p" (random keys)?

Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...

RE: Error 91

(OP)
Evan,
When I am in SW only (after I closed all files) and push random button-nothing change.
When I push F5 button I get a Filter bar.
When I push F10 button (I signed for a macro) I get error message. Thanks for your patience.

RE: Error 91

en20248,

If you run the macro with no documents open, the Set Part = swApp.ActiveDoc will set Part equal to nothing.  So the next part of the code will fail and you will get an Error 91.  I suggest putting in a line of code something to the order of: If Part = Nothing Then Exit Sub.  Put this in just after your Set Part = statement.

Regg

RE: Error 91

(OP)
Regg, Does not work

RE: Error 91

en20248,

Opps!  Should be: If Part Is Nothing Then Exit Sub

Sorry for the confusion.

Regards,

Regg

RE: Error 91

(OP)
Regg, it does work. Thank you and big star for you!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources