Is it possible to run PowersPoint Macros from PowerShell?

Welcome Forums General PowerShell Q&A Is it possible to run PowersPoint Macros from PowerShell?

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
3 years, 3 months ago.

  • Author
    Posts
  • #28158

    Participant
    Topics: 1
    Replies: 1
    Points: 0
    Rank: Member

    I want to run a PowerPoint Macro from a PowerShell script. If i try to run an Excel Macro it works, but if i try to run a PowerPoint Macro it says to me: "type must not be byval".
    Code:

    $ppt = new-object -comobject powerpoint.application
    $pres = $ppt.Presentations.Open($pptSourceFilePath)
    $tst = @('test')
    $pres.Application.Run("TestMain",$tst)
  • #28161

    Participant
    Topics: 8
    Replies: 1190
    Points: 639
    Helping Hand
    Rank: Major Contributor

    It's not Powershell, it's the antiquated Office COM object that's being used. Look for examples on the web specifically running macros with VBA or another programming language, like this: https://support.microsoft.com/en-us/kb/306682

  • #28175

    Participant
    Topics: 1
    Replies: 1
    Points: 0
    Rank: Member

    Thank you. but i cant load an object library (.olb) in Powershell or i dont know how to load it. And as i said, with Excel it is no Problem to call the run method on the COM Object. But PowerPoint wants a safearray of params and this is the Problem. I cant get it to work, no matter what i do; always the same error: type must not be byref. Any Ideas :)?

  • #35571

    Participant
    Topics: 0
    Replies: 1
    Points: 0
    Rank: Member

    Try explicitly passing parameter as type ref:

    $ppt = new-object -comobject powerpoint.application
    $pres = $ppt.Presentations.Open($pptSourceFilePath)
    $tst = @('test')
    $pres.Application.Run("TestMain",[ref]$tst)

    You can also explicitly specify the macro file and module:

    $ppt.Run("MyMacros.pptm!Module1.TestMain",[ref]$tst)

The topic ‘Is it possible to run PowersPoint Macros from PowerShell?’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort