×
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

API Run-Time error '91':

API Run-Time error '91':

API Run-Time error '91':

(OP)
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

RE: API Run-Time error '91':

Are you trying to assign an object not using the set command?

RE: API Run-Time error '91':

Perhaps you could post a snippet of the offending code?

All this machinery making modern music can still be open-hearted.

RE: API Run-Time error '91':

In the VBA editor, on Tools\References, verify if the SW Library box is checked.

Regards

RE: API Run-Time error '91':

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

RE: API Run-Time error '91':

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!"

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