Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetObject(, "Outlook.Application") not working with Outlook open

Tags:

excel

vba

outlook

I am using the below code in an Excel file which can be accessed and used by multiple people. The extract checks to see if Outlook is open before proceeding with the rest of the code.

Dim oOutlook As Object

'Checks to see if Outlook is open
On Error Resume Next
Set oOutlook = GetObject(, "Outlook.Application")
On Error GoTo 0

If oOutlook Is Nothing Then
    MsgBox "Outlook is not open."
    Exit Sub
End If
Set oOutlook = Nothing

The code seems to work for everyone apart from one person/computer. For this one person/computer, even with Outlook open, the line of code Set oOutlook = GetObject(, "Outlook.Application") does not seem recognise that it is open. I've checked the usual things: made sure the VBA references are set up correctly, security settings seem to be the same as everyone else.

Any suggestions would be greatly appreciated.

like image 806
qagofnz Avatar asked Nov 09 '22 11:11

qagofnz


1 Answers

In my experience, I use this to avoid this problem :

On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
    Set oWord = CreateObject("Word.Application")
End If
On Error GoTo 0

But actually I have no clue where the issue come from... It just pass by for me sometimes!

like image 134
R3uK Avatar answered Nov 29 '22 01:11

R3uK