How to programatically invoke a menu item via VB?

B

Bob Stark

I want to build a command line VB application that automates the Secure Pack
plug-in, so that we don't forget that step when we revise our courseware.

From the PowerPoint menu, I issue &Tools; Secure Pac&k; SecurePack
&Wizard...
At that point, a dialog box pops up, and I click &Next; ; etc.

I have a code fragment to dump the menu out; here it is:
Dim X, Y, Z As Integer

With Application.CommandBars("Menu Bar")
For X = 1 To .Controls.Count
Debug.Print .Controls(X).Caption
Debug.Print .Controls(X).Index
For Y = 1 To .Controls(X).Controls.Count
Debug.Print vbTab & .Controls(X).Controls(Y).Caption
If Application.CommandBars("Menu
Bar").Controls(X).Controls(Y).Type = 10 Then
For Z = 1 To .Controls(X).Controls(Y).Controls.Count
Debug.Print vbTab & &
..Controls(X).Controls(Y).Controls(Z).Caption
Next Z
End If
Next Y
Next X
End With

Here is some selected output:
&Options...
SecurePac&k
&About SecurePack...
SecurePack &Wizard...
SecurePack &Configuration...
SecurePack &Help...
Sli&de Show

What method do I want to actually invoke "SecurePack &Wizard..." .Execute"?
An example would be just great.
 
B

Bob Stark

Thanks! That sure is easier.

Of course, one good answer just begets another question.

After I issue:
msPPT.Run "secpack.ppa!initialize"
my code just waits inside of run. Meantime Powerpoint is up, the initial
securePack dialog box is up. But my code to do a FindWindow() and SendKeys
doesn't get control.
Once I manually work my way through SecurePack, my code resumes.
I set up a TimerPop routine to perform the FindWindow() and SendKeys, but it
doesn't pop.
There must be either some setting I must issue so that I run concurrently
with the run method, or there is some totally different technique, perhaps
using PowerPoint events (which I have never used, I'm just vaguely aware of
them).

Suggestions?

Here is the pertinant section of the code, for reference:

3510 Set msPPT = CreateObject("PowerPoint.Application") 'Activate
PowerPoint via OLE
3520
3530 msPPT.Visible = True
3540 If gHidePPT = "YES" Then msPPT.WindowState = ppWindowMinimized

3560 ' Open the PPT file...
3570 WriteStdOut "Opening file: " & SourceFile
3580 msPPT.Presentations.Open SourceFile

TimerID = SetTimer(0, 0, 2000, AddressOf TimerPop)

3590 msPPT.Run "secpack.ppa!initialize"
WriteStdOut "We have returned from Run"

'"SecurePack Wizard Step 1" thru "SecurePack Wizard Step 6"

4270 WriteStdOut "Closing file: " & SourceFile
4280 msPPT.ActivePresentation.Close ' Close the PPT

4300 If msPPT.Presentations.Count = 0 Then 'See if any presentations
are open
4205 If gExitPPT = "YES" Then 'No. Shall we exit
PowerPoint?
4310 msPPT.Quit 'Yes, Exit powerpoint
4315 End If
4320 End If
4330 Set msPPT = Nothing
4350 Exit Function
ErrorCleanup: errMsg
4355
4360 End Function

Sub TimerPop(ByVal hwnd As Long _
, ByVal uMsg As Long _
, ByVal idEvent As Long _
, ByVal dwTime As Long _
)
WriteStdOut "Timerpop entered"

TimerID = KillTimer(0, TimerID)
Dim hMessageBox As Long
'Find dialog box window.
'This is Securepack version specific, need a generic way to
handle...
4600 hMessageBox = FindWindow(vbNullString, "SecurePack Version 1.0")
4610 If hMessageBox Then
WriteStdOut "Found it"
4620 Call SetForegroundWindow(hMessageBox)
4630 SendKeys "&n"
4640 End If
WriteStdOut "Timerpop exit"

End Sub


Regards,
Bob Stark
 

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