We help IT Professionals succeed at work.
Get Started

vba Outlook how to select a new current message

Mark
Mark asked
on
1,139 Views
Last Modified: 2016-02-10
I have the following VBA code:
Public Sub scanFolder(thisCategory as String)
Dim src As Folder
Dim oItem As Object
Dim propertyAccessor As Outlook.propertyAccessor
Set src = Application.ActiveExplorer.CurrentFolder
Dim strHeader As String

For Each oItem In src.Items
    If TypeOf oItem Is Outlook.MailItem Then
        Set propertyAccessor = oItem.propertyAccessor
        header = propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E")
        Dim headerLines() As String
        headerLines() = Split(header, vbCrLf)

        Dim thisHeader As Variant

        For Each thisHeader In headerLines
            If inStr(thisHeader, thisCategory) > 0 then
                  ' set this message as the currently highlighted on in mail folder
            End If
        Next
    End If
Next
End Sub

Open in new window

I want to do 2 things:

1. instead of scanning from the beginning of the selected folder (For Each oItem In src.Items) I want to begin scanning with the message following the currently selected one.

2.  Where I have "set this message ...", I want to set the currently highlighted/selected message in the mail folder to the current oItem.

Thanks
Comment
Watch Question
Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 13 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE