使用参数从PowerShell调用Excel宏 [英] Calling Excel macros from PowerShell with arguments

查看:650
本文介绍了使用参数从PowerShell调用Excel宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Powershell,从脚本调用Excel宏非常简单,例如使用像这个

Using Powershell it's rather easy to call Excel macro's from a script, for example with a script like this:

$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()

但是,我没有设法调用具有一些参数的宏。这是可能的还是编写一个配置文件的最佳方式,宏会在调用时读取?

However, I didn't manage to call a macro with some arguments. Is this possible or is the best way to write a config file that the macro will read when called?

推荐答案

您可以运行宏这样的参数:

You can run a macro with arguments like this:

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

这篇关于使用参数从PowerShell调用Excel宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆