programing

인수를 사용하여 PowerShell에서 Excel 매크로 호출

linuxpc 2023. 8. 14. 22:32
반응형

인수를 사용하여 PowerShell에서 Excel 매크로 호출

Powershell을 사용하면 스크립트에서 Excel 매크로를 쉽게 호출할 수 있습니다. 예를 들어 다음과 같은 스크립트를 사용합니다.

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

하지만, 저는 몇 가지 주장으로 매크로를 호출할 수 없었습니다.이것이 가능합니까 아니면 매크로가 호출될 때 읽을 구성 파일을 작성하는 가장 좋은 방법입니까?

다음과 같은 인수를 사용하여 매크로를 실행할 수 있습니다.

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

언급URL : https://stackoverflow.com/questions/19536241/calling-excel-macros-from-powershell-with-arguments

반응형