Check if Outlook is fully open? Outlook/Options, Start on calendar OK, start on inbox gives error (1 Viewer)

bignose2

Registered User.
Local time
Today, 22:16
Joined
May 2, 2010
Messages
204
Hi,

Got code below from somewhere else & works FINE if Outlook Options are set to open on the calendar

I want it to open on a specific inbox but I get an error "Object variable not set"
oOutlook.ActiveWindow.WindowState = 1 ' causes the error

I assume perhaps not quite fully open because maybe slower to get to my inbox?
It is also fine if I debug, walk through with F8, again a delay I assume.
It is OK if I have a messagebox before but outlook hides MSAccess otherwise I might have used that.

I guess a brief delay or DoEvents might work but being on different computers some may work better/faster than others so prefer a more robust method is there is one.

Code:
    Dim oOutlook        As Object
    Dim sAPPPath        As String
    If IsAppRunning("Outlook.Application") = True Then    'Outlook was already running
        Set oOutlook = GetObject(, "Outlook.Application")    'Bind to existing instance of Outlook
    Else    'Could not get instance of Outlook, so create a new one
        sAPPPath = GetAppExePath("outlook.exe")    'determine outlook's installation path
        Shell (sAPPPath)    'start outlook
       
        Do While Not IsAppRunning("Outlook.Application")
            DoEvents
        Loop
       
        Set oOutlook = GetObject(, "Outlook.Application")    'Bind to existing instance of Outlook
       
'        MsgBox "Wait for outlook"  Works as pauses but outlook is on top/hides access
       
        If Not oOutlook Is Nothing Then
            oOutlook.ActiveWindow.WindowState = 1   ' olMinimized = 1                     THIS IS THE LINE THAT ERRORS (if not default calendar on outlook)
        Else
            Debug.Print "Outlook not yet available. Run MinimizeOutlookWindow again."
        End If

'    If Not oOutlook Is Nothing Then
'        oOutlook.ActiveWindow.WindowState = 1   ' olMinimized = 1
'    Else
'        Debug.Print "Outlook not yet available. Run MinimizeOutlookWindow again."
'    End If

    End If
 
Last edited by a moderator:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 22:16
Joined
Jul 9, 2003
Messages
14,455
I noticed you have yet to receive a reply to your question, hence I am bumping it up the list a tad..
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:16
Joined
Feb 28, 2001
Messages
22,522
When you get this problem, can you tell whether you used an extant instance of Outlook or had to open one?

When I use the "GetObject" method and fail, my next action is to just use "CreateObject" to make an Outlook application object. Look at this article which purportedly opens the InBox as part of its example.

 

Users who are viewing this thread

Top Bottom