Invoking Excel Macros from PowerShell

by Oct 25, 2018

PowerShell can invoke Microsoft Excel sheets and start contained macros. While this would work with an invisible Excel application window, it is a wise idea to keep Excel open (as shown below) to spot warning messages that might appear when you try and run security sensitive things like macros:

# file path to your XLA file with macros $FilePath = "c:\test\file.xla" # macro name to run $Macro = "AddData" $excel = New-Object -ComObject Excel.Application $excel.Visible = $true $wb = $excel.Workbooks.Add($FilePath) $excel.Run($Macro) 

Twitter This Tip! ReTweet this Tip!