Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

API Run-Time error '91':

Status
Not open for further replies.

packmen

Mechanical
Joined
Aug 31, 2001
Messages
77
Location
BR
I having some problems with a macro (Visual Basic) and appears the folow message

Run-time error '91':
Objest variable or With block variable not set

in the debug it stop on saveas comando...

could anyone help-me to fix it?

Thank's

Emerson
 
Are you trying to assign an object not using the set command?
 
Perhaps you could post a snippet of the offending code?

[bat]All this machinery making modern music can still be open-hearted.[bat]
 
In the VBA editor, on Tools\References, verify if the SW Library box is checked.

Regards
 
This type of error can be caused in many ways.

If you are doing this in the SW VBA macro editor, one thing you might want to check is to make sure execution is beginning with your sub main. If you have your cursor elsewhere when you start running/debugging through your code, sometimes the execution starts with whatever procedure/module your cursor is in. This can leave some of your global or module-level objects uninstantiated.

This error can also crop up when the compiler just gets "lost". If you forget to close your if/then blocks with an endif, if you leave a for/next loop open, etc. it may interpret something in the wrong context and throw you this error. So if plan A above doesn't yield results, you may want to just do some more proof-reading of your code.

Best wishes in your quest,
Brenda
 
You are (most likely) using a "SET" type command, and the 'SET' is failing. If this is the case, you have to check your object to see if it is 'NOTHING'.

something likle this:

Dim MyModel as ModelDoc2
Dim DocTitle as string


SET MyModel=swapp.Activedoc ' Sets active SW doc into "MyModel"

DocTitle = MyModel.GetTitle ' gets name of doc in titlebar



... Now, if there were no files open in SW, the "MyModel" object would be "NOTHING", but there would be no error...
UNTIL you tried to get the Title of the document, in which case you would THEN get the "Object variable or With block variable not set" error.

Go backwards in the code from that line, looking for "SET" commands. In the line following a SET command, put in a line of code to check to see if the object is nothing...


SET MyModel=swapp.Activedoc
' ---- insert check for nothing here ----
if MyModel Is Nothing then msgbox "Cant find Object!"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top