Invoke shortcut menu commands using VBA

C

caten

I need to make sure that when I send the outline to Word, the outline is
fully expanded. I created a macro that will:
1. Change to the Outline view
2. Click Expand All
3. Send the outline to Word
4. Return to the original view

When I run this macro, it works the first time, but not the second (and the
third, but not the fourth, etc.) Evidently both the Collapse All and Expand
All buttons actually toggle between fully expanded and fully collapsed. So
this will not work.

I can't find a way to check the expanded/collapsed state of the outline so
that I can Expand All conditionally.

I have noticed that if I select all slides in the outline view (by clicking
Ctrl+A), right-click, and then click Expand, the outline is fully expanded
regardless of its initial state. So this is the command I want to invoke in
my macro.

Is there a way to access controls in a shortcut menu using VBA?

I am using PowerPoint 2002 and targeting PowerPoint 2002, 2003 (and
eventually 2007) users.

Here is what I have so far:

Sub SendOutlineToWord()
Dim strOrigViewType As String 'Original view type
strOrigViewType = ActiveWindow.ViewType

'Change to Outline view
ActiveWindow.ViewType = ppViewOutline

'Click Expand All (expand the outline)
CommandBars.FindControl(Id:=706).Execute

'Click File > Send To > Microsoft Word
CommandBars.FindControl(Id:=30002).Execute
CommandBars.FindControl(Id:=30095).Execute
CommandBars.FindControl(Id:=684).Execute

'Click Outline only and then press Enter
SendKeys "%O{TAB}{ENTER}", True

MsgBox "Outline sent to Microsoft Word."

'Return to original view
ActiveWindow.ViewType = strOrigViewType

End Sub
 
S

Shyam Pillai

Caten,
This code snippet activates the outline tab and then executes the expand all
only if it is need. You will need to adapt this code to use ExecuteMso for
2007 and later.

'======================================
Sub ExpandAll()
Dim oCtl As CommandBarButton
Dim oApp As Object

Set oApp = Application

If oApp.Version <= 11 Then
'2003 and earlier
Set oCtl = CommandBars.FindControl(Id:=706)
If oCtl.State = msoButtonUp Then oCtl.Execute
'Do your stuff here

Else
'2007

End If

End Sub

Sub SetOutlineTab()
Dim oCmdButton As CommandBarButton
Set oCmdButton = CommandBars("Standard").Controls.Add(Id:=6015)
DoEvents
ActiveWindow.ViewType = ppViewNormal

If Not oCmdButton Is Nothing Then
If ActiveWindow.Panes(1).ViewType = ppViewThumbnails Then
oCmdButton.Execute
End If
oCmdButton.Delete
Set oCmdButton = Nothing
End If
End Sub
'=====================================
Regards,
Shyam Pillai

Image Importer Wizard: http://skp.mvps.org/iiw.htm
 

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