Consulting

Results 1 to 2 of 2

Thread: Auto forward macro

  1. #1
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,194
    Location

    Auto forward macro

    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.

    [VBA]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[/VBA]

    Thanks for looking
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post (you may need to click 'Go Advanced')

    Excel 365, Version 2403, Build 17425.20146

  2. #2
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •