Consulting

Results 1 to 2 of 2

Thread: Change subject and forward emails sitting in a folder (inbox)

  1. #1
    VBAX Newbie
    Joined
    Jul 2018
    Posts
    1
    Location

    Change subject and forward emails sitting in a folder (inbox)

    Hello good morning/afternoon/evening/night

    I want a Macro for all emails sitting in Folder "output" under my inbox to change the subject and forward them to an email address.

    So far I have this code (found in internet) and returns with an error: "run time -2147221223 (80040119) - The Operation failed because of a registry or installation problem."

    Can anyone please help me?

    Thanks.

  2. #2
    This is quite straightforward using an Outlook macro e.g.

    Sub ChangeSubjectThenForward()
    Dim olFolder As Folder
    Dim oItem As Object
    Dim olMsg As MailItem
    Set olFolder = Session.GetDefaultFolder(olFolderInbox).folders("output")    'note the folder name is case sensitive!
    
        For Each oItem In olFolder.Items
            If TypeName(oItem) = "MailItem" Then
                oItem.Subject = "The New Subject" 
                oItem.Save
                Set olMsg = oItem.Forward
                olMsg.Recipients.Add "someone@somewhere.com" 'the address of the person you are forwarding to
                olMsg.Send
            End If
        Next oItem
    lbl_Exit:
        Set olFolder = Nothing
        Set oItem = Nothing
        Set olMsg = Nothing
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

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