Mark
asked on
vba Outlook how to select a new current message
I have the following VBA code:
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
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
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
ASKER
Well,that would kind of suck. What I ultimately want to do is search for some user specified criterion, select that as the current message, then continue from there if the user want to find-next. I suppose I could keep track of the last folder and last item, but can a vba macro save persistent values during an outlook session?
ASKER
This looks like it gets the current item:
ActiveExplorer.Selection.i tem(1)
now, to get the next item ...
ActiveExplorer.Selection.i
now, to get the next item ...
ASKER
OK, you're right. Apparently no real way to relate current item to its position in the CurrentFolder that I can see. Once again, hats off to Microsoft for their ability to add complexity ...
How about this ...
1. given For Each item in Application.ActiveExplorer .CurrentFo lder.Items , is there a way to determine if the selected 'item' in the loop is also the selected/highlighted message in the folder? Some attribute perhaps?
2. given the loop variable 'item', above, is there a way to set this as the currently selected/highlighted message in the folder?
How about this ...
1. given For Each item in Application.ActiveExplorer
2. given the loop variable 'item', above, is there a way to set this as the currently selected/highlighted message in the folder?
Well, you could probably figure out which Item the current highlighted is, but how does that help?
~bp
~bp
ASKER
bill Prew:
For Each oItem In Application.ActiveExplorer .CurrentFo lder.Items
if oItem = <curItem> then continue
' if I get here I'm at the item after the current highlighted item
Next
That would be half the problem solved.
Well, you could probably figure out which Item the current highlighted is, but how does that help?Because, assuming the current item is <curitem> (below), I could then ...
For Each oItem In Application.ActiveExplorer
if oItem = <curItem> then continue
' if I get here I'm at the item after the current highlighted item
Next
That would be half the problem solved.
Yes, but you have no idea what order the collection will present the email items in, I don't believe. I'm not even sure it's repeatable.
~bp
~bp
Actually, I may have an idea for this, let me try something here and see if it works as I think it might...
~bp
~bp
ASKER
Bill Prew:
Awaiting your idea ...
you have no idea what order the collection will present the email items inWhether or not it's the order shown on the view windows, my experiments indicate that the VB code seems to scan it in a consistent order.
Awaiting your idea ...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry about the delay -- will check this out tomorrow
ASKER
I'm likewise going to play with this some more later. The project labor level is growing and I did find another way of accomplishing my goal using 'Filter E-mail'. Thanks you've been a great help on this VBA stuff
Welcome.
~bp
~bp
I'll do a little research but I suspect that is the case. You could potentially skip over ones that are marked as Read, but not sure if that helps?
~bp