Avatar of aonecomputers
aonecomputers

asked on 

Forward macro in Outlook 2007

I used to have a macro that worked fine in Outlook 2003 but just upgraded to Outlook 2007 and they no longer work. I have the below macro activated by a button in the toolbar so if I want to forward an email I just click the button. It uses the exemption code which I have heard I no longer need.
The error I am getting is Can't find project or library in the line:
Set myForwarditem = myItem.Forward

Thanks for any help
Public Sub Application_Startup()
 
   ' Reference the items in the Inbox. Because myOlItems is declared
   ' "WithEvents" the ItemAdd event will fire below.
   Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items
 
End Sub
 
Sub Forward2Ed()
 
    Dim myOlApp As New Outlook.Application
    Dim myItem, myForward As Object
   
    Set myItem = myOlApp.ActiveExplorer.Selection.Item(1)
    Set myForwarditem = myItem.Forward
 
    myForwarditem.To = "ed@xxxxx.com"
 
    myForwarditem.Save
    Set objSafeMail = CreateObject("Redemption.SafeMailItem")
    objSafeMail.Item = myForwarditem
    objSafeMail.Send
 
   
    Set myItem = Nothing
    Set myForward = Nothing
    MsgBox "Message Forwarded" ' I would include this line for testing
 
End Sub

Open in new window

Outlook

Avatar of undefined
Last Comment
aonecomputers
ASKER CERTIFIED SOLUTION
Avatar of DavidT543
DavidT543
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of David Lee
David Lee
Flag of United States of America image

The code has a number of problems beyond what DavidT543 listed.  For example, what's the point in lines 1-7 if the code is being run from a button click?  That code is typically used for monitoring a folder so the code can react to new items automatically.  It's also unnecessary to create new instances of an Outlook Application object when the code is running in Outlook.  This is all you need to forward an item in 2007.

Sub Forward2Ed()
    Dim myForward As Object
    Set myForward = Application.ActiveExplorer.Selection.Item(1).Forward
    myForward.To = "ed@xxxxx.com"
    myForward.Send
    Set myForward = Nothing
    'MsgBox "Message Forwarded" ' I would include this line for testing
End Sub

Open in new window

Avatar of aonecomputers
aonecomputers

ASKER

Thanks. I got the code from somewhere else. I guess Outlook 2003 didn't check for the variable initialization. It was working fine for years.
Avatar of aonecomputers
aonecomputers

ASKER

Thank you BlueDevilFan for your help also. I got the code from somewhere else so I don't know why the other lines were there. The macro does work fine w/o the extra lines. What I would also like to do is make the macro be able to work from the message screen also instead of just from the explorer view so that it could work with the results of searches which are not highlighted in the explorer panel. I will start a new project for this.
Outlook
Outlook

Microsoft Outlook is a personal information manager from Microsoft, available as a part of the Microsoft Office suite. Although often used mainly as an email application, it also includes a calendar, task manager, contact manager, note-taker, journal, and web browser.

105K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo