Outlook 2010 Macro to Forward Email Message

In Outlook 2003 I had a macro which forwarded the current email to another mailbox.  This macro worked great.  Below is my code.

Sub Whitelist()
' Forwards email items to the mailbox name Problem Report
        Set ThisItem = Application.ActiveInspector.CurrentItem
        Set fwdItem = ThisItem.Forward
        fwdItem.To = "problemreport@ABCD.com"
        fwdItem.subject = "Whitelist"
        fwdItem.HTMLBody = "<p>Please whitelist the following:</p><p></p>" & vbCrLf & _
        ThisItem.SenderEmailAddress & _
        vbCrLf & fwdItem.HTMLBody
        fwdItem.Send
        MsgBox "An email has been sent to IS"
End Sub

My problem is this.  We just upgraded to Outlook 2010 and now my macro does not work.  I'm getting error messages.

On the line below I'm getting a Run-time error '91: Object variable or With block variable not set
        Set ThisItem = Application.ActiveInspector.CurrentItem

On each of these lines I'm getting a Run-time error '424: Object required
        Set fwdItem = ThisItem.Forward
        fwdItem.To = "problemreport@ABCD.com"
        fwdItem.subject = "Whitelist"
        fwdItem.HTMLBody = "<p>Please whitelist the following:</p><p></p>" & vbCrLf & _
        ThisItem.SenderEmailAddress & _
        vbCrLf & fwdItem.HTMLBody
        fwdItem.Send

Can someone help me get this converted for Outlook 2010 or point me in the right direction.

Thanks in advance!
Senniger1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris BottomleySoftware Quality Lead EngineerCommented:
Try declaring the data types, or removing option explicit from the top of the code module

Chris
Sub Whitelist()
dim thisItem as object
dim fwdItem as object

' Forwards email items to the mailbox name Problem Report
        Set ThisItem = Application.ActiveInspector.CurrentItem
        Set fwdItem = ThisItem.Forward
        fwdItem.To = "problemreport@ABCD.com"
        fwdItem.subject = "Whitelist"
        fwdItem.HTMLBody = "<p>Please whitelist the following:</p><p></p>" & vbCrLf & _
        ThisItem.SenderEmailAddress & _
        vbCrLf & fwdItem.HTMLBody
        fwdItem.Send
        MsgBox "An email has been sent to IS"
End Sub

Open in new window

0
Chris BottomleySoftware Quality Lead EngineerCommented:
Thinking about this again yesterday, option explicit is not likely the issue and dimensioning them as objects really ought not to change anything.

Are you sure you actually have an open mail item when running the sub ... although the question seems superfluous given your familiarity with your code, (the lack of an open mail item WOULD cause this exact error code) I cannot see anything that would justify your problems hence the question.

Chris
0
Chris BottomleySoftware Quality Lead EngineerCommented:
Also for what it's worth if you want it to work on whichever is selected then with a small change the following will process the active item if found and otherwise the currently selected item (first if multiple) in the explorer window or exit.

In this way it is perhaps more tolerant of the problem.

Chris
Sub Whitelist()
Dim thisItem As Object
Dim fwdItem As Object

' Forwards email items to the mailbox name Problem Report
    If TypeName(Application.ActiveWindow) = "Inspector" Then
            Set thisItem = Application.ActiveInspector.CurrentItem
    elseIf TypeName(Application.ActiveWindow) = "Explorer" Then
        Set thisItem = Application.ActiveExplorer.Selection.item(1)
    Else
        Exit Sub
    End If
        
    Set fwdItem = thisItem.Forward
    fwdItem.To = "problemreport@ABCD.com"
    fwdItem.subject = "Whitelist"
    fwdItem.HTMLBody = "<p>Please whitelist the following:</p><p></p>" & vbCrLf & _
    thisItem.SenderEmailAddress & _
    vbCrLf & fwdItem.HTMLBody
    fwdItem.Send
    MsgBox "An email has been sent to IS"

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Senniger1Author Commented:
Perfect.  This was exactly what I needed.
0
Chris BottomleySoftware Quality Lead EngineerCommented:
:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.