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
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':
RE: API Run-Time error '91':
RE: API Run-Time error '91':
Regards
RE: API Run-Time error '91':
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':
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!"