perl+ VBA: raise click event on a button embedded in a Powerpoint slide
Here I have a powerpoint 2010 presentation. On one slide there is an embedded Windows media Player OCX Control. As a simple GUI, I placed 3 buttons labeled Play, Pause, Stop on the same slide.
Using Perl's Win32::OLE module, I want to test if the click event on "Play" plays the file in the embedded windows media player.
Raising the Click event with the mouse, it does.
Using code below, it does not work. Why?
note "Slide $i: " . $slide->{Name};
# switch to "full-screen presentation mode"
PowerpointHelpers::launch_slideshow_from_slide($ole->ActivePresentation, $i);
sleep 3;
#does not work
$btnplay->{OLEForm开发者_如何学编程at}->Object()->btnPlay_Click();
sleep 3;
# return to slide edit-mode
# PowerpointHelpers::exit_show($ole);
This is the VBA procedure that is supposed to run:
Public Sub btnPlay_Click()
Init
PlayVideo (Player.URL)
End Sub
As you can see this just calls two custom functions that play an avi file. It does work correctly in interactive use. but not via VBA automation .
Meanwhile, I have tried quite a few variations of the line
$btnplay->{OLEFormat}->Object()->btnPlay_Click();
but none work.
Here is a dump of the $btnplay object:
OLE object's properties:
Accelerator .............................
AutoSize ................................ 0
BackColor ............................... 8421504
BackStyle ............................... 1
Caption ................................. Video abspielen
Enabled ................................. 1
Font .................................... [IFont]
ForeColor ............................... 0
Height .................................. 28.375
Left .................................... 18.75
Locked .................................. 0
MouseIcon ............................... <undef>
MousePointer ............................ 0
Name .................................... btnPlay
Picture ................................. <undef>
PicturePosition ......................... 7
TakeFocusOnClick ........................ 1
Top ..................................... 382.875
Visible ................................. 1
Width ................................... 124.75
WordWrap ................................ 0
ZOrderPosition .......................... 9
This works!
my $s = $ole->ActivePresentation->SlideShowWindow->View->Slide;
$s->Application->Run('btnPlay_Click', '');
This does not work, it is here for completeness. I was referring to this code in the comments.
This is my perl code, where I attempt to call the btnPlay_Click event handler directly:
my $s = $ole->SlideShowWindows(1)->View->Slide;
PowerpointHelpers::_dump_ole_obj($s, 1);
Win32::OLE->Option(Warn => 3);
$s->btnPlay_Click(); ### DOES NOT WORK (for me)
Win32::OLE->Option(Warn => 0);
Error Output of btnPlay_Click();
Win32::OLE(0.1709) error 0x80020003: "Member not found"
in METHOD/PROPERTYGET "" at 06-mediaplayer--button-clicks-ok.t line 127
slide object: Output of _dump_ole_obj
OLE object's properties:
Application ............................. [_Application]
Background .............................. [ShapeRange]
BackgroundStyle ......................... 0
ColorScheme ............................. [ColorScheme]
Comments ................................ [Comments]
CustomLayout ............................ [CustomLayout]
CustomerData ............................ [CustomerData]
Design .................................. [Design]
DisplayMasterShapes ..................... -1
FollowMasterBackground .................. 0
HasNotesPage ............................ -1
HeadersFooters .......................... [HeadersFooters]
Hyperlinks .............................. [Hyperlinks]
Layout .................................. 1
Master .................................. [_Master]
Name .................................... Slide7
NotesPage ............................... [SlideRange]
Parent .................................. [_Presentation]
PrintSteps .............................. 1
Shapes .................................. [Shapes]
SlideID ................................. 262
SlideIndex .............................. 24
SlideNumber ............................. 24
SlideShowTransition ..................... [SlideShowTransition]
Tags .................................... [Tags]
ThemeColorScheme ........................ [ThemeColorScheme]
TimeLine ................................ [TimeLine]
sectionIndex ............................ 1
More Funcnames:
Cut()
Duplicate()
Export()
GetTypeInfo()
Invoke()
MoveToSectionStart()
QueryInterface()
Release()
SectionNumber()
精彩评论