I've had good success with working with Excel and PowerShell except I fail to find how to add or move a sheet to the last position. It appears to me that the Add and Move methods accept similar arguments so I'm just going to focus on attempting to get it to work with the optional After argument. Here is what I have.
#get my sheets
$Sheets = $WorkBook.WorkSheets
#find the index of the last one
$SheetCount = $Sheets.Count
#create an object reference to the last sheet
$LastSheet = $WorkBook.Sheets | WHERE {$_.Index -eq $SheetCount}
#attempt to create the new sheet after the last one
$NewSheet = $Sheets.Add($LastSheet After)
It does not work. Do any of you know how to create a sheet in the last position with PowerShell?
Joe Moyle
#get my sheets
$Sheets = $WorkBook.WorkSheets
#find the index of the last one
$SheetCount = $Sheets.Count
#create an object reference to the last sheet
$LastSheet = $WorkBook.Sheets | WHERE {$_.Index -eq $SheetCount}
#attempt to create the new sheet after the last one
$NewSheet = $Sheets.Add($LastSheet After)
It does not work. Do any of you know how to create a sheet in the last position with PowerShell?
Joe Moyle