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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating object reference to program already running 1

Status
Not open for further replies.

rdgerken

Technical User
Jul 8, 2002
108
If a program that has it's object model exposed via VBA is already running, how can you get a reference to that object model without creating your own instance?

Thanks.

Ryan
 
Can you just do the same as I do for Word?

Sub startword()
On Error Resume Next 'ignore errors
Set wordapp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set wordapp = CreateObject(&quot;word.application&quot;)
End If
Err.Clear ' Clear Err object in case error occurred.
On Error GoTo 0 'Resume normal error processing
End Sub

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
That doesn't work... seems that the application needs to be registered so that the GetObject works.

Perhaps Word and any other office program already has these registrations?

If anyone else can help me out here - please input!

Thanks
 
You have added a reference to this other program in Project/References?
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Yes John... I have certainly done that.

I can get a window handle for it, but still no luck.
 
The choice of starting a new instance or use an already running instance of a COM server lies in the architecture created by the programmer of the COM server. You as a client cannot determine whether or not you will get a completely new instance of the server.

Otherwise it wouldn't be of much use to have the ability of choosing the instance creation as a programmer of a COM server.

Also I do not think that it is possible to get a reference to an already running COM server if you are not the client that started it. This would mean that you could run in serious trouble if you were the client that started the COM server in the first place. I cannot imagine that COM will be kind enough to just hand you an interface to a COM object that another client created.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top