Solved

VBA Compatibility between Word/Outlook - 2003 & 2007

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

708 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

17 Experts available now in Live!

Get 1:1 Help Now