I'm basically trying to create a Power Shell function which takes in a variable set to an excel worksheet and returns the last used row and column.
I know the code works outside of a function. Here's what it looks like in my function.
Function FindRange ([string] $path)
{
$mainRng = $path.UsedRange.Cells
$ColCount = $mainRng.Columns.Count
$RowCount = $mainRng.Rows.Count
$xRow = $RowCount
$xCol = $ColCount
Write-Host "function DEBUG xrow:" $xRow
Write-Host "function DEBUG xcol: " $xCol
Write-Host "function path:" $path
}
FindRange $BTWSRawSheets
$BTWSRawSheets is:
$BTWSRawSheets = $wbBTWS.worksheets | where {$_.name -eq "Export Worksheet"}
The output of Write-Host "function path:" $path is
function path: System.__ComObject
Is anyone able to help me figure out how to pass the excel worksheet in as the parameter? I've spent a few hours researching and trying but have had no luck.