Hello!
I am having trouble converting my PowerPoint VBA script into a Perl script.
Here is the VBA script:
Dim slide As slide
Dim shape As shape
For Each slide In ActivePresentation.Slides
For Each shape In slide.Shapes
If shape.TextFrame.HasText Then
If shape.HasTextFrame Then
shape.TextFrame.TextRange.Text = Replace(shape.TextFra
+me.TextRange.Text, "PM3", "TCF6203")
End If
End If
Next shape
Next slide
End Sub
And here is what I have in Perl so far:
use strict;
use warnings;
use Cwd;
use Win32::OLE;
use Win32::PowerPoint;
use Win32::OLE::Const 'Microsoft Office';
use Win32::OLE::Const 'Microsoft PowerPoint';
use Win32::Process;
use Win32::OLE::Enum;
$Win32::OLE::Warn = 3;
my $file = "PM30306901A SMP Limit Switch.pptx";
my $dir = getcwd();
my $filename = $dir . '\\' . $file;
print ("Starting PowerPoint\n");
my $process = Win32::OLE->GetActiveObject('Powerpoint.Application')||
Win32::OLE->new('Powerpoint.Application', 'Quit');
print ( "Opening '$filename'\n" );
my $ppt = $process->Presentations->Open($filename);
my $pp = Win32::PowerPoint->new;
$file =~ s/PM3/TCF6203/;
$filename = "$dir/$file'";
print ( "Replacing 'PM3' with 'TCF6203'\n" );
my @activeslides = $process->ActivePresentation->Slides;
foreach my $slide (@activeslides) {
foreach my $shape ($slide->Shapes){
if ($shape->TextFrame->HasText){
if ($shape->HasTextFrame){
$shape->TextFrame->TextRange->Text = Replace($shape->T
+extFrame->TextRange->Text, "PM3", "TCF6203");
}
}
}
}
print ( "Saving '$filename'\n" );
$pp->save_presentation($filename);
The problem occurs when it gets to the foreach loops. It says "Shapes not found in Slides collection." Is there a way to define an object as a shape and slide in Perl? Basically I need help converting the VBA script to the Perl Script.