Solved

VBA Compatibility between Word/Outlook - 2003 & 2007

Posted on 2009-07-01
2
173 Views
Last Modified: 2012-05-07
I have a Word template that generates an email in Outlook.

My problem is that some users are on Office 2007, and some are on 2003, so when the macro runs, it brings up errors because the required reference library is missing, and because I don't have both versions of Outlook installed on my PC, I can't select both.

Is there a way to get this to work, regardless of which version of Word or Outlook the user is on?
0
Comment
Question by:lp3535
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 24760038
lp3535 said:
>>Is there a way to get this to work, regardless of which version of Word or Outlook the user is on?

Yes: use late binding.  In late binding, you do not set a reference to the external library, and you declare
objects as type Object rather than the proper class from the external library.  You also have to avoid using
named constants from the external library.

The snippet below shows an example of late binding:

Dim olApp As Object
Dim olMsg As Object

Set olApp = CreateObject("Outlook.Application")
Set olMsg = olApp.CreateItem(0)
With olMsg
    .To = "X@z.com"
    .CC = "y@z.com"
    .BCC = "z@z.com"
    .Subject = "subject"
    .Body = "body"
    .Attachments.Add "c:\folder\subfolder\foo.xls"
    .Send
End With

Set olMsg = Nothing
Set olApp = Nothing
0
 

Author Comment

by:lp3535
ID: 24760902
Brilliant.  Thanks for that, it works perfectly.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outlook Free & Paid Tools
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question