Solved

VBA Compatibility between Word/Outlook - 2003 & 2007

Posted on 2009-07-01
2
172 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
If you don't know how to downgrade, my instructions below should be helpful.
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now