Is there any way to rename or/and delete corrupted ranged names, which include spaces, e.g. “ACVCutoff_4 1” in Excel file with help of powershell? I got stuck on this. Renaming or deleting names fails.
$Excel = New-Object -Com Excel.Application
$wbTo = $Excel.workbooks.open($path)
foreach($name in $wbTo.Names)
{
$name.Name = $tt -replace '\s+', '_' # name is not affected
$name.delete() # returns an error Exception calling "Delete" with "0" argument(s): "Exception from HRESULT: 0x800A03EC"
}
What I have tried:
- Including Name manager add-in does not solve the issue.
- “Check R1C1 Reference Style” (check the link) – how can it be achieved by writing a code?
Any other suggestions? I would appreciate your help
I am using powershell v2 and Excel 2007/2010.
That’s the file with broken names: XlsWithBrokenNames
SOLUTION BY Chris Neilsen for those who are also stuck on this:
#$wbTo - is workbook with corrupt names
$tempFilePath = $path + "temp.xlsm"
$goodFilePath = $path + "cleanFile.xls"
$wbTo.SaveAs($tempFilePath,52) #save as xlsm
$wbTemp = $Excel.workbooks.open($tempFilePath) # open target
# delete names here
$wbTemp.SaveAs($goodFilePath,56) #save as xls
All direct manipulation of the corrupt names i have tried has failed!
But, here’s a possible alternative:
SaveAsyour workbook as a.xlsmYou should get a dialog complaining about invalid names, with a option to rename and aOk to Allbutton. Once saved, close and reopen the file,Save Asan.xlsand you should be good to go