Eng-Tips is the largest forum for Engineering Professionals on the Internet.

Members share and learn making Eng-Tips Forums the best source of engineering information on the Internet!

  • Congratulations dmapguru on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 91

Status
Not open for further replies.

en20248

Mechanical
Joined
Sep 30, 2004
Messages
38
Location
US
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.
 
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...
 
Hello Evan,
After i close a document and push signed keybutton i get an error message.
 
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...
 
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.
 
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...
 
Evan, I added End command, but it did not help.
 
Is the code above all you are using? If not, please post all your code.

Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...
 
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


 
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...
 
Evan,
The keybutton I signed is F10; SW2005 SP0.0
Thank you.
 
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...
 
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.
 
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
 
en20248,

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

Sorry for the confusion.

Regards,

Regg
 
Regg, it does work. Thank you and big star for you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top