In your code you have a try-catch around the delete. Most likely it is failing to find the sheets and therefore not deleting them. Put some logic into the catch block to report the error so you can see why it is failing. Ultimately you should debug this by putting a breakpoint on that code and step through it to see exactly what is going wrong.
Open save file has old xml sheet names in it and causes a warning?
Jonathan Brotto
1,076
Reputation points
Open save file has old xml sheet names in it and causes a warning?
I used a code to add sheets and then I rename them, but it does not work. It skips the delete part I wrote.
The part that adds and rename sheets
Dim addSheets As Excel.Sheets = Globals.ThisAddIn.Application.Sheets
addSheets.Add()
addSheets.Add()
addSheets.Add()
Dim sheetRename As Excel.Worksheet = Globals.ThisAddIn.Application.Sheets("Sheet1")
sheetRename.Name = "Raw SAP"
sheetRename = Globals.ThisAddIn.Application.Sheets("Sheet2")
sheetRename.Name = "Territory Summary"
sheetRename = Globals.ThisAddIn.Application.Sheets("Sheet3")
sheetRename.Name = "Customer Summary"
sheetRename = Globals.ThisAddIn.Application.Sheets("Sheet4")
sheetRename.Name = "Product Summary"
'Sort sheets in correct order
sheetRename = Globals.ThisAddIn.Application.Sheets("Raw SAP")
sheetRename.Move(Before:=Globals.ThisAddIn.Application.Worksheets(1))
sheetRename = Globals.ThisAddIn.Application.Sheets("Customer Summary")
sheetRename.Move(After:=Globals.ThisAddIn.Application.Worksheets(3))
sheetRename = Globals.ThisAddIn.Application.Sheets("Product Summary")
sheetRename.Move(After:=Globals.ThisAddIn.Application.Worksheets(4))
sheetRename = Globals.ThisAddIn.Application.Sheets("Territory Summary")
sheetRename.Move(Before:=Globals.ThisAddIn.Application.Worksheets(2))
Delete portion that does not work it seems.
Try
sheetRename = Globals.ThisAddIn.Application.Sheets("Sheet2")
sheetRename.Delete()
sheetRename = Globals.ThisAddIn.Application.Sheets("Sheet3")
sheetRename.Delete()
sheetRename = Globals.ThisAddIn.Application.Sheets("Sheet4")
sheetRename.Delete()
Catch ex As Exception
End Try