Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Open an Excel spreadsheet with powershell getting error

$
0
0

I am trying to open an excel file within power shell. Here is the code i am using 

$excel

=New-Object-com excel.application

 

 

$excel

.Visible=$True

 

 

 

$excelfile

="C:\Users\adm_kmccallion\Desktop\AssetInventory.xlsx"

 

 

$sheet

='Test'

 

 

$ou

="ctnet.com/Eton"

 

 

 

#$ExcelWorkbook = $Excel.Workbooks.Open($ExcelFile, 2, $True)

$ExcelWorkbook

=$Excel.workbooks.open("C:\Users\adm_kmccallion\Desktop\AssetInventory.xlsx")

 

$ExcelWorkSheet

=$Excel.Worksheets.Item($Sheet)

 

but i am getting the following error

 

Method invocation failed because [System.__ComObject] doesn't contain a method named 'open'.

At C:\Users\adm_kmccallion\Desktop\test.ps1:11 char:39

+ $ExcelWorkbook = $Excel.workbooks.open <<<< ("C:\Users\adm_kmccallion\Desktop\AssetInventory.xlsx")

+ CategoryInfo : InvalidOperation: (open:String) [], RuntimeException

+ FullyQualifiedErrorId : MethodNotFound

 

Any idea why?




Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>