Powershell cannot create Excel object

305 Views Asked by At

I have a Win11 PC with Office365 and another Win11 PC with Office 2010

The PC with Office 2010 cannot create an Excel object in Powershell.

Here is my script:

$excel = New-Object -ComObject excel.application 
$excel.Visible = $true
$workbook = $excel.Workbooks.Add(1)
$Worksheet = $workbook.worksheets.Item(1)
$ActiveWindow = $excel.ActiveWindow

Works fine on the Office365 machine, creates and opens a spreadsheet.

On the Office 2010 machine I get this error:

Exception setting "Visible": "Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 
'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the 
interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception 
from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))."
At line:2 char:1

I am missing something obvious which has got me baffled.

Any ideas or suggestions.

The Office2010 PC has been repaired using a recovery USB to fix other issues. The trial version of Office365 was uninstalled and Office 2010 installed

0

There are 0 best solutions below