Getobject and Creatobject

P

Paradigm

I am using the following code

Function fnStartAcad()
On Error Resume
Set acadapp = GetObject(, "AutoCAD.Application")
If Err Then
Debug.Print Err.Description
Err.clear
Set acadapp = CreateObject("AutoCAD.Application")
If Err Then
MsgBox Err.Description
Exit Function
End If
End If
On Error GoTo 0
acadapp.Visible = True
End Function

To start Autocad but the same thing seems to happen when I start other
programs. The first time I run it I can see Acad.exe in the list of
processes in task manager but the code seems to hang on the createobject
line. If I end the process I eventually get an error message saying it
cannot create the obkect. If I run the code a second time after ending the
process it works fine.
Can anyone shed any light on this.
Alec
 
A

Albert D. Kallal

same thing seems to happen when I start other
programs.

Try it with word...seems to work ok for me....

On Error Resume Next
Set acadapp = GetObject(, "Word.Application")
If Err Then
Debug.Print Err.Description
Err.Clear
Set acadapp = CreateObject("Word.Application")
If Err Then
MsgBox Err.Description
Exit Function
End If
End If
On Error GoTo 0
acadapp.Visible = True
Can anyone shed any light on this.

The above works for me, so I have absolute no idea about auto-cad. (don't
have auto cad). Perhaps something in AutoCAD does NOT allow more then one
copy to run on the computer? Perhaps AutoCAD don't allow automation as per
above?

For example, the above code would NOT work if you were trying to use the
above to launch a 2nd copy (or even 1st copy) of ms-access when using the
**runtime** version of ms-access. So, if you try

createObject("Access.Application")

The above works ok in full edition of ms-access, but in the runtime, the
above will fail...
(because the runtime requires you to launch access with a file open, so you
can't create a instance of the runtime ms-access unless you supply a file to
open, and you can't do that until AFTER you created the instance). However,
I don't think this is your problem with regards to auto-cad. You might try
some of the auto cad groups and see what they say.

I assume your code compiles....I assume you using option explicit for all
modules? Does this work as a mde (or acccDe). Perhaps your code in some
form's module, and acadapp is not defined as a true global variable? (if it
goes out of scope, then the running instance of the application can also go
out of scope - but, in most cases, I find the running instance does stay
running).

These are a few trouble shoots I would try.

However, since your posted code works fine on my machine (using word), then
this is likey some autoCAD issue....
 
P

Paradigm

I think I traced the problem, after the code list I used the statement

acadapp.AppActivate

in word it would be

WordObj.Activate

when I remove the AppActivate everything seems to work as intended.
Thanks for your help
Alec
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top