Retrieving and setting current sort order

R

Rey

Howdy all.
Have short VBScript that creates an Outlook obj and looks for a mail
item with a specific subject line.

Was wondering how to obtain the user's current inbox sort order so I
can change it to descending to ensure the most recent email w/desired
subject is the first mail item found and then return it to the user's
previous selection.

I can set the sort below but have not yet found how to obtain the
current sort order...
' set sort order of inbox
olInBox.Items.Sort "Received", True

Appreciate your suggestions/comments.

Thank you,

Rey
 
R

Rey

Found what works for me...and hopefully for others having encountered
similar problem.

Had to define a vbScript var as olInBoxItems and SET this to the
default InBox folder Items collection.
Then the sort desc work.

So here's the vbScript code:

' create Outlook app
set objOutLook = CreateObject("Outlook.Application")
'msgbox "OutLook app obj created"

set olNameSpace = objOutLook.GetNameSpace("MAPI")
'msgbox "OutLook NameSpace obj created"

' get inbox
set olInBox = olNameSpace.GetDefaultFolder(olFolderInBox)

'msgbox "OutLook InBox obj created"

' set sort order of inbox - DOESN'T SORT
'olInBox.Items.Sort "[Received]", True

SET olInBoxItems = olInBox.Items

' now sort desc - WORKS
olInboxItems.Sort "[Received]", True

' find the email subj
'set olMailItem = olInBox.Items.Find(strFilter)
set olMailItem = olInBoxItems.Find(strFilter)


' found email
if not (olMailItem is Nothing) then

' file into which email body is saved to for later reading
strTempFile = "\LienReleaseBody.txt"

' proc to write out & read contents of msgbody
strLiens = GetAndReadMessageBody(olMailItem.Body, strTMPFolder &
strTempFile)

end if

' closing Outlook objs
SET olInBoxItems = Nothing
set olMailItem = Nothing
set olInbox = Nothing
set olNameSpace = Nothing
set objOutLook = Nothing



Similar code works in vb.net.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top