Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBA Compatibility between Word/Outlook - 2003 & 2007

Posted on 2009-07-01
2
Medium Priority
?
182 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 93

Accepted Solution

by:
Patrick Matthews earned 2000 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

916 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