WCPeterson
11-27-2012, 12:08 PM
I am trying to organize my email better. I am wanting to populate the 'Companies' field of emails with a project name and then sort into folders based on that field. Most of my emails are replies to my emails, so setting this field will allow me to quickly sort. My problem is that I want to select multiple emails and set the Companies field. However, the code below only sets the first email's Companies field and not the rest. The MsgBox shows that the email appears to get set but when the macro completes the first email isn't populated until you select a new email, but only the first email is populated. None of the others get populated.
Would anybody have a solution to this?
Note: If you go to View Settings -> Columns, setting 'All Journal fields' and then Add 'Company', this field will show up as a field in your list of emails.
Sub PopulateCompaniesField()
Dim olNS As Outlook.NameSpace
Dim objSelection As Outlook.Selection
Dim objMsg As Object
Dim i As Integer
Set olNS = GetNamespace("MAPI")
' Get the collection of selected objects.
Set objSelection = Application.ActiveExplorer.Selection
For i = 1 To objSelection.Count
objSelection.Item(i).Companies = "Test"
MsgBox i & " " & objSelection.Item(i).Companies
Next i
End Sub
Would anybody have a solution to this?
Note: If you go to View Settings -> Columns, setting 'All Journal fields' and then Add 'Company', this field will show up as a field in your list of emails.
Sub PopulateCompaniesField()
Dim olNS As Outlook.NameSpace
Dim objSelection As Outlook.Selection
Dim objMsg As Object
Dim i As Integer
Set olNS = GetNamespace("MAPI")
' Get the collection of selected objects.
Set objSelection = Application.ActiveExplorer.Selection
For i = 1 To objSelection.Count
objSelection.Item(i).Companies = "Test"
MsgBox i & " " & objSelection.Item(i).Companies
Next i
End Sub