Word作为COM对象没有设置属性的属性/功能



很抱歉,这对我来说很陌生,但是我有一个以下工作的脚本,如以下功能:

$wd = new-object -comobject word.application

但是当我打印com对象时,它具有所有属性的空/空白值。

PS C:UsersXXX> $wd

Application                       : 
Creator                           : 
Parent                            : 
Name                              : 
Documents                         : 
Windows                           : 
ActiveDocument                    : 
ActiveWindow                      : 
Selection                         : 

,它无法设置任何功能或执行任何功能

PS C:UsersXXX> $wd.Visible = $true
Exception setting "Visible": "Unable to cast COM object of type 'Microsoft.Office.Interop.Word.ApplicationClass' to interface type 'Microsoft.Office.Interop.Word._Application'. This 
operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error: Error loading 
type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY))."
At line:1 char:1
+ $wd.Visible = $true
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting

我尝试浏览相关问题,但无法查看错误是否完全相同。我运行了所有Windows更新,并进行了维修安装。(运行Windows 10和Office 2013)

有时word/excel/ppt com对象的作用疯狂。因此,Microsoft本身不建议将其用于自动化目的(对不起,但找不到来源)。但是无论我个人一直在使用这些:)。

系统还原关闭和重新填写PowerShell Session 实际上为我解决了这些问题。

不幸的是,我无法找到一种处理此问题的程序化方法。因此,期待进一步的答案。( 1)

最新更新