collapse a specific mail folder from a macro in Outlook 2007

U

udo

Hi,
My Outlook 2007 archives emails to a "archivel" folder tree structure
that is parallel to my mailbox folders.
I've written a macro that switches between a folder and its archive
(see below)
As a safety measure, I want the "archivel" folder collapsed
altogether
when I switch back to the non-archive folder, so that I don't confuse
its folders with the normal ones - any Idea how I do this?

Thanx in advance.


----------------------------------


Sub SwitchBetweenCurrentFolderAndItsArchive()
Dim names As Collection
Set names = New Collection
Dim cf As Folder
Set cf = Application.ActiveExplorer.CurrentFolder
Set f = cf
Do While Not f Is Nothing And TypeOf f Is MAPIFolder
names.Add (f.Name)
Set f = f.Parent
Loop


Dim newf As Folder
If names(names.Count) <> "Archivel Folders" Then
Set newf = f.Folders("Archivel Folders")
MsgBox "Switching from a folder to its ARCHIVE"
Else
Set newf = f.GetDefaultFolder(olFolderInbox).Parent
MsgBox "Switching from an archive back to its FOLDER"
End If


' remove 'mailbox' item
names.Remove (names.Count)


While names.Count > 0
'MsgBox names.Item(names.Count)
Set newf = newf.Folders(names.Item(names.Count))
names.Remove (names.Count)
Wend


Set Application.ActiveExplorer.CurrentFolder = newf
End Sub
 
K

Ken Slovak - [MVP - Outlook]

You can't control whether a store is expanded or not in the folder list or
navigation pane in general. No way to do what you want.
 
U

udo

Thanks, Ken.

As an alternative, can I have my macro open the archive folder in a
new view, rather than navigate to it in the current view?

You can't control whether a store is expanded or not in the folder list or
navigation pane in general. No way to do what you want.

--
Ken Slovak
[MVP - Outlook]http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.http://www.slovaktech.com/products.htm




Hi,
My Outlook 2007 archives emails to a "archivel" folder tree structure
that is parallel to my mailbox folders.
I've written a macro that switches between a folder and its archive
(see below)
As a safety measure, I want the "archivel" folder collapsed
altogether
when I switch back to the non-archive folder, so that I don't confuse
its folders with the normal ones - any Idea how I do this?
Thanx in advance.

Sub SwitchBetweenCurrentFolderAndItsArchive()
Dim names As Collection
Set names = New Collection
Dim cf As Folder
Set cf = Application.ActiveExplorer.CurrentFolder
Set f = cf
Do While Not f Is Nothing And TypeOf f Is MAPIFolder
   names.Add (f.Name)
   Set f = f.Parent
Loop
Dim newf As Folder
If names(names.Count) <> "Archivel Folders" Then
Set newf = f.Folders("Archivel Folders")
MsgBox "Switching from a folder to its ARCHIVE"
Else
Set newf = f.GetDefaultFolder(olFolderInbox).Parent
MsgBox "Switching from an archive back to its FOLDER"
End If
' remove 'mailbox' item
names.Remove (names.Count)
While names.Count > 0
   'MsgBox names.Item(names.Count)
   Set newf = newf.Folders(names.Item(names.Count))
   names.Remove (names.Count)
Wend
Set Application.ActiveExplorer.CurrentFolder = newf
End Sub- Hide quoted text -

- Show quoted text -
 
K

Ken Slovak - [MVP - Outlook]

Not quite sure what you mean.

If you want the archive PST shown in a new, different window then you'd add
an Explorer to the Explorers collection (Explorers.Add) and set the
CurrentFolder of the new Explorer to display a folder in your PST file.

If the want the current window (Explorer) to show that PST folder using a
different view you set the ActiveExplorer.View object to whatever named view
you want or you set the ActiveExplorer.View.XML to the explicit view XML you
want to use.




Thanks, Ken.

As an alternative, can I have my macro open the archive folder in a
new view, rather than navigate to it in the current view?
 
U

udo

Thanks, Ken - I used Explorers.Add and that was just what I need.
I saw there's a parameter for setting which display to use, but I
couldn't get rid of the To-Do Bar - how do I do that?
 
K

Ken Slovak - [MVP - Outlook]

No way to do that using code that I know of. The folder display mode options
will open it normally or with no Navigation Pane. Even the
olFolderDisplayFolderOnly setting doesn't do what you want.




Thanks, Ken - I used Explorers.Add and that was just what I need.
I saw there's a parameter for setting which display to use, but I
couldn't get rid of the To-Do Bar - how do I do that?
 

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