Created
December 20, 2012 08:49
-
-
Save jongalloway/4343892 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-type -AssemblyName office | |
$find = "SPEAKER" | |
$replace = "Jon Galloway" | |
function ReplaceText { | |
param( | |
[object]$shape, | |
[string]$find, | |
[string]$replace | |
) | |
if ($shape.HasTextFrame) | |
{ | |
$textFrame = $shape.TextFrame | |
$textRange = $textFrame.TextRange | |
$textRange.Replace($find, $replace, 0, $msoFalse, $msoFalse) | |
<# | |
#Use this if above replacement causes formatting to be lost. | |
$paragraphs = $textRange.Paragraphs() | |
foreach ($paragraph in $paragraphs) | |
{ | |
$text = $paragraph.Text | |
if($text.Contains($find)) { | |
$text = $text.Replace($find, $replace) | |
$paragraph.Text = $text | |
} | |
} | |
#> | |
} | |
} | |
$Application = New-Object -ComObject powerpoint.application | |
$msoTrue = [Microsoft.Office.Core.MsoTriState]::msoTrue | |
$msoFalse = [Microsoft.Office.Core.MsoTriState]::msoFalse | |
$application.visible = $msoTrue | |
$path = "C:\Users\Jon\SkyDrive\Projects\Git\" | |
Get-ChildItem -Path $path -Include "*.pptx" -Recurse | | |
ForEach-Object { | |
"Modifying $_.FullName" | |
#Open presentation with ReadOnly:False, Untitled:False, Visible:True | |
$presentation = $application.Presentations.Open($_.fullname, $msoFalse, $msoFalse, $msoTrue) | |
foreach ($slide in $presentation.Slides) { | |
foreach ($shape in $slide.Shapes) { | |
# [Microsoft.Office.Core.MsoShapeType]::msoGroup | |
if ($shape.Type -eq 6) { | |
foreach ($item in $shape.GroupItems) { | |
ReplaceText $item $find $replace | |
} | |
} else { | |
ReplaceText $shape $find $replace | |
} | |
} | |
} | |
$presentation.Save() | |
$presentation.Close() | |
} | |
$application.quit() | |
$application = $null | |
[gc]::collect() | |
[gc]::WaitForPendingFinalizers() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
as an [object] I guess, but doesn't it support Dictionary instead of HashTable?