Outlook VBA - Perform action on selected items

McSpaff

New Member
Joined
Dec 13, 2015
Messages
7
Hi all,

I'm still working my way through Macros and although Excel brought me here originally, I'm branching out in to other MS programs.

My current project is a Macro that edits the subject line of selected emails. The background is that a number of users all work out of a shared mailbox, and when an email is actioned, the user is required to add their initials to the end of the subject before filing it in the relevant mailbox.

I Googled the majority of the below and I'm finding that although it correctly edits the email title by appending " - JC" to the end of the subject, it only does so for the first email that is selected.

When I step through the Macro, I can see that it loops the correct number of times based on the number of emails highlighted but I cannot understand why it only updates the first email in the selection.


Code:
Public Sub InitialEmail()

    Dim currentExplorer As Explorer
    Dim Selection As Selection
     
    Dim obj As MailItem
 
    Set currentExplorer = Application.ActiveExplorer
    Set Selection = currentExplorer.Selection
 
 
    For Each obj In Selection
  
     With obj
  
           .Subject = obj.Subject & " - JC"
      
     End With
 
    Next
 
End Sub

Any help would be much appreciated.

Thanks in advance.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I tested it (2010) and the emails had to be open. Just selecting from the list didn't affect them.
 
Upvote 0
In that case, it's there any possibility of modifying the code so that it will make the change on selected emails without the need to have them open?
 
Upvote 0
Add .save after you .subject line
 
Upvote 0

Forum statistics

Threads
1,215,824
Messages
6,127,103
Members
449,358
Latest member
Snowinx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top