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