Hello,
I’m playing around with Powershell, trying to achieve my goal…obviously I have some problems.
First of all I really don’t understand why if I open 4 Word 2010 docs, these code returns only 2 docs..
$msword = [Runtime.Interopservices.Marshal]::GetActiveObject(‘Word.Application’)
$msword.documents | select Name
Name
TEST DOC - Copy.docx
TEST DOC - Copy - Copy - Copy.docx
I also open other 2 docs, “TEST DOC - Copy - Copy.docx” and “TEST DOC.docx”.
A similar issue occurs with PowerPoint.
I open 3 .pptx:
TEST DOC.pptx
TEST DOC - Copy.pptx
TEST DOC - Copy - Copy.pptx
Now if I give these commands, PS correctly returns all 3 .pptx:
$pp = [Runtime.Interopservices.Marshal]::GetActiveObject(‘Powerpoint.Application’)
$pp.presentations | select Name
When I open 3 .pptx, these commands only returns 2 .pptx:
Name
TEST DOC.pptx
TEST DOC - Copy - Copy.pptx
TEST DOC - Copy.pptx
But this only save 2 .pptx (“TEST DOC.pptx” and “TEST DOC - Copy - Copy.pptx”)
SaveFolder
$SAVEASDIR = "$ENV:USERPROFILE\Desktop\Security Saves"
if(!(Test-Path -Path $SAVEASDIR )){ New-Item -ItemType directory -Path $SAVEASDIR }
#PowerPoint
$MSPPOINT = [Runtime.Interopservices.Marshal]::GetActiveObject(‘Powerpoint.Application’)
$MSPPOINTDOCS = $MSPPOINT.Presentations
$MSPPOINTDIRNAME = (Get-Date).tostring(“dd-MM-yyyy_hh-mm-ss”)
$MSPPOINTSAVEASDIR = New-Item -itemType Directory -Path “$SAVEASDIR” -Name $MSPPOINTDIRNAME" Doc PowerPoint"
foreach ($presentation in $MSPPOINTDOCS) {
$presentation.SaveAs(“$MSPPOINTSAVEASDIR$($presentation.name)”)
$presentation.Close()
}
Excel seems to work as expected (to me :-)).
Any help would be greatly appreciated.
Thanks,
Andrea