VBA crash late binding Outlook

User avatar
ErikJan
BronzeLounger
Posts: 1249
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

VBA crash late binding Outlook

Post by ErikJan »

I had code that worked a few months back. I did not change the code and now Excel crashes immediately after execution of this line:

Code: Select all

Set olApp = CreateObject("Outlook.Application")

User avatar
HansV
Administrator
Posts: 78500
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA crash late binding Outlook

Post by HansV »

Did you happen to switch to "New Outlook" in the meantime?
Best wishes,
Hans

User avatar
ErikJan
BronzeLounger
Posts: 1249
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: VBA crash late binding Outlook

Post by ErikJan »

Not AFAIK, I'm using MSO365 and thus Outlook Desktop

User avatar
HansV
Administrator
Posts: 78500
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA crash late binding Outlook

Post by HansV »

Yes, but Microsoft released a new version of the desktop app last year and has been trying to get users to switch.
It's easy recognizable: its icon has NEW in tiny letters.

S2534.png

Something else: does it make a difference if Outlook is already running or not?
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
ErikJan
BronzeLounger
Posts: 1249
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: VBA crash late binding Outlook

Post by ErikJan »

I believe I use the old desktop App. And the crash is also there if Outlook is not running (I double checked in Task Manager)

User avatar
HansV
Administrator
Posts: 78500
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA crash late binding Outlook

Post by HansV »

Does the computer have a registry key

Computer\HKEY_CLASSES_ROOT\PackagedCom\ProgIdIndex\Outlook.Application
Best wishes,
Hans

User avatar
ErikJan
BronzeLounger
Posts: 1249
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: VBA crash late binding Outlook

Post by ErikJan »

No, I found that too when I Googled and checked it. The key is not there (regretfully)

User avatar
HansV
Administrator
Posts: 78500
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA crash late binding Outlook

Post by HansV »

I don't know what to suggest next, sorry.
Best wishes,
Hans

User avatar
ErikJan
BronzeLounger
Posts: 1249
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: VBA crash late binding Outlook

Post by ErikJan »

Thanks for trying Hans. It's mysterious as a month or so ago (when I wrote this) this worked flawlessly. Now I can't access Outlook anymore from Excel VBA...
I just hope someone else might have an idea then

snb
4StarLounger
Posts: 580
Joined: 14 Nov 2012, 16:06

Re: VBA crash late binding Outlook

Post by snb »

Can you open the VBEditor in Outlook ?

User avatar
ErikJan
BronzeLounger
Posts: 1249
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: VBA crash late binding Outlook

Post by ErikJan »

Yes

snb
4StarLounger
Posts: 580
Joined: 14 Nov 2012, 16:06

Re: VBA crash late binding Outlook

Post by snb »

can you see the references in the VBEditor tab extra

Did you test from Excel:

Code: Select all

Sub M_snb()
  Application.ActivateMicrosoftApp 3
End Sub

User avatar
ErikJan
BronzeLounger
Posts: 1249
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: VBA crash late binding Outlook

Post by ErikJan »

You mean the VBE screen in Outlook? Tab "Extra"?? I can see References in the Tools tab in Outlook desktop, yes.

You code starts another instance of OutLook.

snb
4StarLounger
Posts: 580
Joined: 14 Nov 2012, 16:06

Re: VBA crash late binding Outlook

Post by snb »

In that case maybe:

Code: Select all

Sub M_snb()
  Application.ActivateMicrosoftApp 3
  with getobject(Outlook.Application,"")
     '   your code here
  end with
End Sub
Otherwise: is early binding in Excel functioning correctly ?

PS. Dow Chemical, I presume.

User avatar
ErikJan
BronzeLounger
Posts: 1249
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: VBA crash late binding Outlook

Post by ErikJan »

I need to early bind to make you code work I presume.

My code is late binding, I tried to early bind but could get that to work (yet): later code then fails here: "Set olNsp = olApp.GetNamespace("MAPI")"

snb
4StarLounger
Posts: 580
Joined: 14 Nov 2012, 16:06

Re: VBA crash late binding Outlook

Post by snb »

Is it possible in the 'references' in Excel to add the reference to Outlook ?

User avatar
ErikJan
BronzeLounger
Posts: 1249
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: VBA crash late binding Outlook

Post by ErikJan »

Yes, that's early binding... see my problem with that in my last post...

User avatar
ErikJan
BronzeLounger
Posts: 1249
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: VBA crash late binding Outlook

Post by ErikJan »

Thanks for all the tips. I still have the problem and will post in another forum to see if that might help me.
In case I do find a solution, I'll report that back here.

User avatar
ErikJan
BronzeLounger
Posts: 1249
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: VBA crash late binding Outlook

Post by ErikJan »

Here's my promised update.

The problem isn't solved but I got a few suggestions that are acceptable as workarounds.

My problem was this line (which crashed Excel immediately):
CreateObject("Outlook.Application")
What I found myself when I Googled is this:
CreateObject("Outlook.Application.16")
And that works!

Another workaround was to use GetObject (that works for me) and a user suggested this code:

Code: Select all

Sub Test()
Dim x As Object

On Error Resume Next
Set x = GetObject(, "Outlook.Application")
On Error GoTo 0

If x Is Nothing Then
   Shell ("Outlook")
   Set x = GetObject(, "Outlook.Application")
End If
End Sub
That works as well.

FYI, the whole thread in the other forum is here: https://www.excelforum.com/excel-progra ... tlook.html