Macro to Change sort and collapse groups in Mail folder

  • Thread starter Thread starter Brad
  • Start date Start date
B

Brad

Thanks for taking the time to read my question.

I'd like to write a macro that when run, changes the sort order of the mail
folder I'm in (Inbox or any sub folder) by From, and then Collapses All
Groups.

I've searched the internet and not found what I'm looking for. Can this be
done?

Thanks,

Brad
 
I haven't played with it myself. However, this prints the current view
definition into the debug window:

Debug.Print Application.ActiveExplorer.CurrentFolder.CurrentView.Xml

I'd play with the folder view, print CurrentView.Xml, and see what changes.
If you have found how to define the settings you're looking for, you can
edit the xml property. See also the Apply, and the Save method of the View
object.

--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>


Am Fri, 15 Jan 2010 08:36:01 -0800 schrieb Brad:
 
I do this sort of thing all the time in my addins. I usually grab the XML in
the VBA Immediate window and put it in Notepad for easy editing. I then
modify the view as desired and use the modified XML file as my base for
setting up whatever custom view I want.

For sorting this is the sort of XML you need:

<orderby>
<order>
<heading>Received</heading>
<prop>urn:schemas:httpmail:datereceived</prop>
<type>datetime</type>
<sort>desc</sort>
</order>
</orderby>

You can have up to 3 sort fields within that <orderby> tag. Properties are
identified using DASL property tags, so you need to pick those up for your
view properties. You can also set grouping using tags for that.
 
Hi Ken,

Also found this. I made a new view. Am I able to just apply this new view
via VBA?

Thanks,

Brad
 
Ok, came up with a solution.

I make a custom view by:
View>Current View>Define View
and made a new view as I needed.

Then I found this code and made a macro button on my tool bar for the code.
Works like a charm.

Sub ChangeCurrentView()
Dim myOlExp As Outlook.Explorer

Set myOlExp = Application.ActiveExplorer
If myOlExp.CurrentView = "Messages" Then
myOlExp.CurrentView = "Group And Sort"
Else
myOlExp.CurrentView = "Messages"
End If
End Sub

Thanks to everyone on this post for all your help.

Brad
 
Back
Top