View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default Excel export to Outlook:- Missing Microsoft Outlook 16.0 object library

The problem is that MS forces Outlook to the current/latest MSO install
version. OK if you use early binding for development (if needed) but
better you switch to late binding before you distribute your project...

Check if outlook is running 1st: (It doesn't allow multiple instances)

Private Function bOutlookAvailable() As Boolean
Dim appOL As Object, bWasRunning As Boolean

' Attempt to get a reference to a currently open
' instance of Outlook.
On Error Resume Next
Set appOL = GetObject(, "Outlook.Application")
' If this fails, attempt to start a new instance.
If appOL Is Nothing Then
Set appOL = CreateObject("Outlook.Application")
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 appOL Is Nothing Then
' If we started Outlook we need to close it.
If Not bWasRunning Then appOL.Quit
Set appOL = Nothing: bOutlookAvailable = True
Else
bOutlookAvailable = False
End If
End Function 'bOutlookAvailable

You could modify it to leave the CreateObject instance running, but be
careful to also check bWasRunning to see if you should close it. Now
your code should ref whatever version is on the host machine. I suggest
using a global var for this...

Public gbOutlookIsRunning As Boolean

...and use it to test after you put the local in it...

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

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion