Trying to group the headline together was quite a challenge ...
I am trying to run several PowerPoint macros from PowerShell. I did a good job running macros from Powershell for Excel. When I run macros in Excel, the Run () method from the COM object will take many arguments, depending on whether the macro has any parameters. However, on the other hand, the PowerPoint Run () method expects parameters, and I cannot decide how to pass them.
My macro expects one line to be passed, I googled plentifully and came up with a short one. I always get this error:
Mistake:
type must not be ByRef
I put together a very simple PoC for PowerPoint in PowerShell:
The code:
# PowerPoint test Add-type -AssemblyName office $PowerPoint = New-Object -comobject PowerPoint.Application $PowerPoint.Visible = [Microsoft.Office.Core.MsoTriState]::msoTrue $presentation2 = $PowerPoint.Presentations.open("C:\macros.pptm") $presentation = $PowerPoint.Presentations.open("C:\Test For Macros.pptx") $PowerPoint.run("macros.pptm!IAM",[ref]"Feb") $presentation.save() $presentation.close() $presentation2.close() $PowerPoint.quit()
The macro itself simply moves the text across all fields; it works great when run from PowerPoint.
Requirements:
Now I want to automate this through several files and slides.
PowerPoint COM object documentation. Run the method , specifying the requirement for two parameters.
vba powershell powerpoint-vba powerpoint
Chris
source share