PDA

View Full Version : [SOLVED:] Add string to beginning of subject for a selected received email and save



jkhvbid
05-15-2018, 09:03 AM
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

gmayor
05-15-2018, 08:38 PM
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

jkhvbid
05-16-2018, 06:03 AM
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!