Consulting

Results 1 to 3 of 3

Thread: Add string to beginning of subject for a selected received email and save

  1. #1
    VBAX Newbie
    Joined
    May 2018
    Posts
    2
    Location

    Add string to beginning of subject for a selected received email and save

    I would like to add a string to the subject of a selected email and have it saved.
    The code I have right now works to a point. I click on the target email, run the
    macro and the subject is changed but I have to open the email and save it
    for it to work.

    Sub ChangeSubject()
    Dim strSubject As String
    Dim olMail As MailItem
    On Error GoTo ErrHandler
            Set olMail = Application.ActiveExplorer.Selection.Item(1)
            strSubject = olMail.Subject
            olMail.Subject = "(TEST) " & strSubject
    Exit Sub
    ErrHandler:
    Beep
    End Sub
    Last edited by Aussiebear; 04-19-2023 at 03:24 PM. Reason: Adjusted the code tags

  2. #2
    Add the Save command to the macro
    Sub ChangeSubject()
    Dim strSubject As String
    Dim olMail As MailItem
    
        On Error GoTo ErrHandler
        Set olMail = Application.ActiveExplorer.Selection.Item(1)
        strSubject = olMail.Subject
        olMail.Subject = "(TEST) " & strSubject
        olMail.Save
        Set olMail = Nothing
        Exit Sub
    ErrHandler:
        Beep
    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

  3. #3
    VBAX Newbie
    Joined
    May 2018
    Posts
    2
    Location
    Quote Originally Posted by gmayor View Post
    Add the Save command to the macro
    Sub ChangeSubject()
    Dim strSubject As String
    Dim olMail As MailItem
    
        On Error GoTo ErrHandler
        Set olMail = Application.ActiveExplorer.Selection.Item(1)
        strSubject = olMail.Subject
        olMail.Subject = "(TEST) " & strSubject
        olMail.Save
        Set olMail = Nothing
        Exit Sub
    ErrHandler:
        Beep
    End Sub
    PERFECT! Thanks!

Tags for this Thread

Posting Permissions

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