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.
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: