ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel automation fails from PowerShell when PIa are installed. (https://www.excelbanter.com/excel-programming/440724-excel-automation-fails-powershell-when-pia-installed.html)

Shiv

Excel automation fails from PowerShell when PIa are installed.
 
Below Script to automate Excel runs fine if PIA are not installed.
$xl=new-object -comObject Excel.Application
$file="D:\test\test.csv"
$xl.visible = $true
$wbk = $xl.Workbooks.Open("$file")
$wks = $wbk.worksheets.item(1)
$r1=$wks.Range("A1:D1")
$r2=$wks.Range("A2:D2")
$xl.Union($r1, $r2)

If PIa are installed it fails on line $xl.Union($r1, $r2). I determined
that it's happening because Windows Powershell is not able to typecast
_ComObject to Microsoft.Office.Interop.Excel.Range. Any pointers?

thanks.


All times are GMT +1. The time now is 11:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com