2016-08-02 157 views
-1

以下程序在文件夹位置“c:\ mfolder”中的一组文件上运行PowerShell中名为“Macro1”的Excel VBA宏。我怎样才能复制它的Word VBA宏?Word VBA宏通过Powershell

***** runexcel.ps1 ******

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

请阅读此:http://stackoverflow.com/help/how-to-ask –

回答

1

要通过PowerShell的打开微软的Word,请使用以下命令:

$word = new-object –comobject Word.Application 

在你的循环,使用此打开每个文件:

$doc = $word.documents.open($file.fullname) 

您应该能够根据您提供的脚本调整其余部分。