I have been experiencing troubles when running a PowerPoint Macro from Powershell (running Excel macros already works). As there is not much info on the web regarding this topic, I'm willing that you will be able to help me.
I'm trying to automate reporting in my work area and the flow is to query data from MS SQL Server, import data into Excel file, refresh charts and then build the final report with PowerPoint slides.
PowerPoint file's charts' are linked with the Excel (via File -> Edit Links to Files) and after selecting the specific chart, Chart Tools menu appears where on the Design tab I just click "Refresh Data" and the chart refreshes. I already have a macro which refreshes data automatically for me. Now I want to call that macro from Powershell script. Please see my code below:
$ppt = New-Object -ComObject Powerpoint.Application
$FilePath = '\\c03d03\public\Data\uvall\IBNB\OnePager.pptm'
$presentation = $ppt.presentations.Open($FilePath)
$ppt.Visible = $true
$app = $ppt.Application
$tst = @('test')
$presentation.Application.Run("RefreshData",[ref]$tst) / 1st way
$app.Run("RefreshData", [ref]@()) / 2nd way
$app.Run("RefreshData", @()) / 3rd way
$app.Run("RefreshData") / 4th way
$presentation.save()
$presentation.close()
$ppt.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($ppt)
And none of these 4 ways of calling a macro works. Sometimes it just returns an error that the "Sub or function not defined", even if it's truly defined, sometimes it returns "You cannot call a method on a null-valued expression" and other errors.
Related:
Run PowerPoint Macro from PowerShell
Please also be aware that I'm using Office 2013
Maybe someone can carefully look into this and help me out!