Word范围复制和粘贴不适用于PS4

时间:2017-05-05 06:31:02

标签: powershell ms-word powershell-v4.0

在下面的代码中,$range2.Paste($copy)行无法在PS4及以下版本上运行。

  

错误:异常类型:System.Management.Automation.MethodInvocationException   异常消息:使用“1”参数调用“Paste”的异常:“对象引用未设置为对象的实例。”

最小代码:

$word = New-Object -ComObject word.application
$word.visible = $false
$word2 = New-Object -ComObject word.application
$word2.visible = $false
$doc = $word.documents.open($source)
$doc2 = $word2.documents.add($template)
$range = $doc.Range()
$copy=""
$copy = $range.Copy()
$range2 = $doc2.Range()
$range2.Paste($copy)
$doc2.saveas([ref]$destination,[ref]$saveFormat::wdFormatDocument)

0 个答案:

没有答案