I am running the ff. script - its purpose is to blank out some cells in an EXCEL file ‘MyFile.xlsx’ and Save it to the same:
1 - $Excel = New-Object -Comobject Excel.Application
2 - $Excel.Visible = $True
3 - $Excel.DisplayAlerts = $False
4 - $wbookn = “C:\Users\XXC\Documents\MyFile.xlsx”
5 - $book = $Excel.Workbooks.Open($wbookn)
6 - $sheet = $book.Worksheets.Item(“wks1”)
7 - $sheet.Activate() | Out-Null
8 - $sheet.Range(“B2:F1001”).ClearContents()
Line 9 works, but why does ‘$book.Save’ create an error?
9 - $book.SaveAs($wbookn,51)
Line 9 above works just fine. But when I changed it to
it fails to save the contents. Additionally I get these extra lines of messages on the screen:
void Save ()
from Powershell. I must be missing something with the use of the Save method within Powershell.
Would be grateful for any tips, advice or pointers to the right answer.