Manipulating Excel with powershell

-1

Good day everybody, so we are trying to automate some Excel and have encountered a few errors, so we have the script that is listed below, but we ran into 3 different errors.

Could someone help us identify where the script went wrong?

The error that we are getting are:

Exception calling  "Open" with  "1" arguments : "Server error. (excpetion  HRESULT: 0x80010105 (RPC_E_SERVERFAU
LT))"
C:\Users\Montage\Desktop\blockadp.ps1:9 char:34
+ $workbook = $excel.workbooks.open <<<< ($excelMacrosFile);
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

Cant call a method with  NULL.
C:\Users\Montage\Desktop\blockadp.ps1:10 char:39
+ $worksheet = $workbook.worksheets.item <<<< (1);
    + CategoryInfo          : InvalidOperation: (item:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Exception calling "Run" with "31" arguments: "server error. (excpetion from HRESULT: 0x80010105 (RPC_E_SERVERFAU
LT))"
C:\Users\Montage\Desktop\blockadp.ps1:11 char:11
+ $excel.Run <<<< ("Convert", $inputExcelFile, $outputADSFile);
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

cannot call a method with NULL.
C:\Users\Montage\Desktop\blockadp.ps1:13 char:16
+ $workbook.close <<<< ();
    + CategoryInfo          : InvalidOperation: (close:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

The script itself:

$excelMacrosFile = "C:\Users\Montage\Desktop\friday.xls";
$inputExcelFile = "C:\Users\Montage\Desktop\25.05.17.xls";
$outputADSFile = "C:\Users\Montage\Desktop\25.05.17.adp";

$excel = new-object -comobject excel.application;

$workbook = $excel.workbooks.open($excelMacrosFile);
$worksheet = $workbook.worksheets.item(1);
$excel.Run("Convert", $inputExcelFile, $outputADSFile);
#$workbook.save();
$workbook.close();
$excel.quit();

Even if I try this only "https://support.jamsscheduler.com/hc/en-us/articles/206191918-How-to-Automate-the-opening-of-an-Excel-Spreadsheet-in-Powershell"

$excelMacrosFile = "C:\Users\Montage\Desktop\friday.xls";
$excel = new-object -comobject excel.application;
$workbook = $excel.workbooks.open($excelMacrosFile);

Then I still get the same error

Exception calling "Open" with "1" argument(s): "The server threw an exception. (Exception from HRESULT: 0x80010105
(RPC_E_SERVERFAULT))"

It's also not permissions as mentioned below since this works:

$test = Get-Content 'C:\Users\Montage\Desktop\25.05.17.xls
excel
powershell
cmd
automation
asked on Stack Overflow May 24, 2017 by AudioTroubler • edited May 24, 2017 by AudioTroubler

1 Answer

0

The problem was that the version of Microsoft Office that was installed was x86. When the system itself is x64.

Testing this on x64 office showed no errors, and the script worked as intended.

answered on Stack Overflow May 25, 2017 by AudioTroubler

User contributions licensed under CC BY-SA 3.0