Share via


Outlook.Application not working

Question

Sunday, February 26, 2017 9:20 PM

Good evening,

I have a macro which uses Excel to create a pdf file then store it and send a copy through Outlook to several users.

which just happens to be the computer that needs it most.  It stick on Dim mon_appli As Outlook.Application.

Could anyone point me as to why the third computer may not like it?

First part of the code attached below.

Thanks for your help and advice.

Option Explicit

Sub createmail()

Dim mon_appli As Outlook.Application
Dim mon_mail As Outlook.mailitem
Dim FileName As String
Dim Path As String

All replies (2)

Sunday, February 26, 2017 10:16 PM

Does the computer on which the code fails have an older version of Outlook than you? If so, it is better to use late binding:

1) Change

Dim mon_appli As Outlook.Application
Dim mon_mail As Outlook.mailitem

to

Dim mon_appli As Object
Dim mon_mail As Object

2) Create mon_appli by using

Set mon_appli = CreateObject("Outlook.Application")

3) Replace Outlook-specific constants such as olMailItem with their values (in this example: 0). You can look up the values in the Object Browser in the Visual Basic Editor in Outlook.

4) Finally, remove the reference to the Microsoft Outlook n.0 Object Library from Tools > References...

See Re: EARLY binding and LATE binding

Regards, Hans Vogelaar (http://www.eileenslounge.com)


Monday, February 27, 2017 8:04 AM

Thanks Hans for the help.

Hi Lind89,

Please take a look at Hans' reply and see if it is helpful. Just want to add that here we mainly focus Office client related questions, there is so much about macro here.

For macro related questions, better to post in the following dedicated forum, that's where most of the VBA experts hang out. You should get more professional responses there:

https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=outlookdev

Regards,

Ethan Hua

Please remember to mark the replies as answers if they helped.
If you have feedback for TechNet Subscriber Support, contact [email protected].