使用参数从PowerShell调用Excelmacros

使用Powershell可以很容易地从脚本调用Excelmacros,例如使用如下脚本:

$excel = new-object -comobject excel.application $excelFiles = Get-ChildItem -Path C:\fso -Include *.xls, *.xlsm -Recurse Foreach($file in $excelFiles) { $workbook = $excel.workbooks.open($file.fullname) $worksheet = $workbook.worksheets.item(1) $excel.Run("CreateChart") $workbook.save() $workbook.close() } $excel.quit() 

但是,我没有设法用一些论据来调用macros。 这是可能的,或者是编写一个configuration文件,macros调用时将被读取的最佳方式?

你可以用这样的参数运行macros:

 $excel.Run('CreateChart', 'arg1', 'arg2', ...)