Word as COM object has no attributes/ability to set attributes

0

I'm sorry that this is quite alien to me, but I had a previously working script that functioned like the following:

$wd = new-object -comobject word.application

but when I print the COM object it has empty/blank values for all attributes.

PS C:\Users\XXX> $wd


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

And it cannot set any or perform any functions

PS C:\Users\XXX> $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

I tried browsing related questions but was unable to see if the mistakes are exactly identical. I've run all Windows updates and did a repair installation of Office. (Running Windows 10 and Office 2013)

powershell
ms-word
com
asked on Stack Overflow Mar 7, 2019 by AdamO

1 Answer

0

Sometimes Word/Excel/PPT COM Objects are acting wildly. Thus using these is not recommended for automation purposes by Microsoft itself (sorry but couldn't find the source). But whatever personally I use those all the time :).

System Restore or closing and repoening the Powershell Session actually fixes those problems for me.

Unfortunately I couldn't figured out a programmatic way to handle this yet. So looking forward for further answers. (+1)

answered on Stack Overflow Mar 8, 2019 by Umut Alihan Dikel

User contributions licensed under CC BY-SA 3.0