VBA code to Collapse All Groups

B

Bruce

I have been looking for a small section of code that will duplicate the
collapse all feature you can find from within the Tasks From the View Menu
-> Expand/Collapse Groups -> Collapse All Groups.

I have searched all over with no success. I am a 'part time VBA novice' so
I am at the end of my capabilities for figuring this out. Anyone got a
suggestion of where I could find such a piece of code?

Thanks,
Bruce
 
I

iwork2ski

Thanks for the tip. Still does not seem to work. I put msgbox to see if the
execute was occurring and the code made it into the if statement and
displayed the msgbox. But the collapsing of the groups does not occur. Any
ideas? Could the ID have changed on my machine? How do I find the ID?

thanks,
Bruce

Sub TaskViewActions()
'Called by a button click
ChangeView ("Active Tasks By Action (GTD)")
End Sub
Sub TaskViewProjects()
'Called by a button click
ChangeView ("Active Tasks By Project (GTD)")
End Sub
Sub ChangeView(View As String)
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Set myOlExp = myOlApp.ActiveExplorer
If myOlExp.CurrentFolder = "Tasks" Then
myOlExp.CurrentView = View
End If
CollapseAllTasks
End Sub
Sub CollapseAllTasks()
Dim objInsp
Dim colCB
Dim objCBB
On Error Resume Next
Set objInsp = Item.GetInspector
Set colCB = objInsp.CommandBars
Set objCBB = colCB.FindControl(, 1917)
If Not objCBB Is Nothing Then
objCBB.Execute
msgbox("If you see this the objCBB.Execute occurred.")
End If
Set objCBB = Nothing
Set colCB = Nothing
Set objInsp = Nothing
End Sub
 
S

Sue Mosher [MVP-Outlook]

If you don't want to write your own code to recurse the Explorer.CommandBars
and Inspector.CommandBars collections, you can use either the CommandBars
Browser or Outlook Spy tools listed at http://wwwoutlookcode.com/d/vb.htm#tools

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
I

iwork2ski

I used Outlook Spy and confirmed that 1917 was the ID for the control. I
still could not get it to collapse the groups. (there is no error message) I
then tried replacing te .FindControl with the actual menu command

CommandBars.Item("Menu
Bar").Controls.Item("&View").Controls.Item("E&xpand/Collapse
Groups").Controls.Item("Co&llapse All Groups")

This didn't work either.

In a task view when I right click and choose Collapse All Groups it works.
Where would I look for the Control ID for the controls displayed when right
clicking over a task?

Regards,
Bruce
 
S

Sue Mosher [MVP-Outlook]

Ah, I see at least part of the problem. Your CollapseAllTasks procedure is working with the CommandBars of the current item window (Item.GetInspector), not the current folder window (Application.ActiveExplorer).

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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