From: David Kerber on
Running VB6 on Win7 x64.

Is there a way of getting my vb6 app to be able to use the outlook 11
object lib while outlook 2003 is running?

Set olk = New Outlook.Application

works fine when outlook is not running on my machine, but when I have
Outlook 2003 running, I get "ActiveX component can't create object"

Is there a way of letting this be shared?

D

From: David Kerber on
In article <MPG.264e21f767ef30e19896fe(a)news.onecommunications.net>,
ns_dkerber(a)ns_warrenrogersassociates.com says...
>
> Running VB6 on Win7 x64.
>
> Is there a way of getting my vb6 app to be able to use the outlook 11
> object lib while outlook 2003 is running?
>
> Set olk = New Outlook.Application
>
> works fine when outlook is not running on my machine, but when I have
> Outlook 2003 running, I get "ActiveX component can't create object"
>
> Is there a way of letting this be shared?
>
> D

This seems to work fine on a different machine with 32-bit XP. So now
the question is: is it Win7, or 64-bit that is killing me?

D
From: MikeD on

"David Kerber" <ns_dkerber(a)ns_warrenrogersassociates.com> wrote in message
news:MPG.264e21f767ef30e19896fe(a)news.onecommunications.net...
> Running VB6 on Win7 x64.
>
> Is there a way of getting my vb6 app to be able to use the outlook 11
> object lib while outlook 2003 is running?
>
> Set olk = New Outlook.Application
>
> works fine when outlook is not running on my machine, but when I have
> Outlook 2003 running, I get "ActiveX component can't create object"
>
> Is there a way of letting this be shared?
>


Try calling GetObject first. Use error trapping. Then if olk is Nothing, create new instance.

air code example

On Error Resume Next
set olk = GetObject(,"Outlook.Application")
On Error GoTo EH 'normal error handling

If olk Is Nothing Then
Set olk = New Outlook.Application
End If


--
Mike


From: GS on
After serious thinking David Kerber wrote :
> Running VB6 on Win7 x64.
>
> Is there a way of getting my vb6 app to be able to use the outlook 11
> object lib while outlook 2003 is running?
>
> Set olk = New Outlook.Application
>
> works fine when outlook is not running on my machine, but when I have
> Outlook 2003 running, I get "ActiveX component can't create object"
>
> Is there a way of letting this be shared?
>
> D

Contrary to how most the other MSO apps work, Outlook does not allow
multiple instances of itself. We can't create a 'New' instance of it
when it's already running, and so we're forced to 'hijack' a running
instance if there is one OR create our own instance if not. Hijacking a
user's instance of any app is a risky affair that is generally not
recommended, but in this case M$ gives us no choice. Thus, MikeD's
advice is mandatory when trying to automate Outlook.

To add to that advice, I suggest you use a 'flag' (i.e.:
bNewOlkInstance) so your app knows if you hijacked a running instance
or not. In this case, you want to leave it running if already in use.
Otherwise, if you create your own instance you'll probably want to shut
it down when you're done with it if you have no reason for turning it
over to the user. In either case your object refs need to be destroyed
when no longer needed (standard cleanup<g>).

Regards,
Garry


From: GS on
I forgot to mention that you should also move MikeD's 'Set...= New...'
statement into the previous error handler the GetObject() is in in case
Outlook was not installed.

here's a function I use to determine how to proceed based on whether
the MSO app I'm trying to automate is available or even installed. Note
that this is a stand-alone test (using 'late binding') that cleans up
after itself, and so is not designed to actually create the instance
you will use. If it returns TRUE then you can automate however you
like. The test allows you to take advantage of 'early binding' at
design time (as is the case indicated by you here) and avoid raising an
error if you persist to use that code at runtime.

Public Function bOutlookAvailable() As Boolean

'These could also be module level or global
Dim bWasRunning As Boolean
Dim olApp As Object

On Error Resume Next
'Attempt to get a reference to a currently open
'instance of Outlook.
Set olApp = GetObject(, "Outlook.Application")
'If this fails, attempt to start a new instance.
If olApp Is Nothing Then
Set olApp = CreateObject("Outlook.Application")
'If this fails then Outlook is not installed.
Else
'Otherwise flag that Outlook was already running
'so that we don't try to close it.
bWasRunning = True
End If
On Error GoTo 0

'Return the result of the test.
If Not olApp Is Nothing Then
'If we started Outlook here we need to close it.
If Not bWasRunning Then olApp.Quit
Set olApp = Nothing
bOutlookAvailable = True
Else
bOutlookAvailable = False
End If

End Function

If you make bWasRunning a global var or ByRef arg then your app can
determine what to do if it was running or if it isn't installed.

Garry