PDA

View Full Version : Auto forward macro



georgiboy
05-16-2009, 08:17 AM
Hi all,

I have some code that has been chopped up a little. As far as i can see the code should work, please could someone explain why it does not work?

The code does fire when a new email arrives i have proved that, so i think there is a fault with the forward/send part.

Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
Dim objNS As Outlook.NameSpace

Set objNS = GetNamespace("MAPI")
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Items_ItemAdd(ByVal item As Object)
Dim Msg As Outlook.MailItem
Dim NewForward As Outlook.MailItem

If item.Class = olMail Then
If Left$(item.Subject, 1) = "1" Then

Set Msg = item
Set NewForward = Msg.Forward
With NewForward
.Subject = "Hi"
.To = "example@example.com"
.HTMLBody = "Hi again"
'.Send
.Display
End With

End If
End If

Set NewForward = Nothing
Set Msg = Nothing

End Sub

Thanks for looking

JP2112
05-17-2009, 03:48 PM
Did you paste it into ThisOutlookSession module? Did you restart Outlook after entering the code?

If so, try setting a breakpoint on the "Private Sub Items_ItemAdd" line and either wait for a qualifying email to arrive, or drag an existing email over to your Inbox, and see what happens. Step through the code and check the value of each variable to make sure each value is expected for the email being processed.

HTH,
JP