Buzz4693 has asked for the wisdom of the Perl Monks concerning the following question:
And here is what I have in Perl so far: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
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.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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: PowerPoint Help
by poj (Abbot) on Dec 20, 2014 at 15:21 UTC | |
by Buzz4693 (Initiate) on Dec 23, 2014 at 18:00 UTC | |
|
Re: PowerPoint Help
by CountZero (Bishop) on Dec 20, 2014 at 13:57 UTC |