Home » excel » excel – System.__ComObject does not contain a method named 'Range'

excel – System.__ComObject does not contain a method named 'Range'

Posted by: admin April 23, 2020 Leave a comment

Questions:

Powershell with excel novice here. I’m learning how to interact with excel via powershell and discovered a ‘range’ feature on several sites.

Strange thing is, this feature does not work on my system and returns the following error: Method invocation failed because [System.__ComObject] does not contain a method named 'Range'.

Can anyone help me with having my powershell use the range feature?

$xl = new-object -comobject excel.application
$xl.visible = $false
$Workbook = $xl.workbooks.open(“c:\test.csv")
$Workbook.Range("A:Z").Find('05/**/**')
How to&Answers:

Find is a member of Range, but Range is not a member of the Workbook object. It is a property of Worksheet.

I recommend you check out the documentation, especially as you may need to use FindNext and FindPrevious.

$Workbook  = $xl.workbooks.open(“c:\test.csv")
$Worksheet = $Workbook.Worksheets.Item(1)
$Workbook.Range("A:Z").Find('05/**/**')