VBSCript code to rename excel sheet;Rename Excel Sheet VBScript;Excel sheet rename using VBScript;Excel sheet rename programmatically VBScript
How to rename Excel worksheet from VBScript
1) The following code renames an excel worksheet in VBScript.
To rename an excel sheet we need to open the excel file, rename the sheets, save and close it. Now we can start coding to open and rename the first excel sheet from "Sheet1" to "NewName".
To rename an excel sheet we need to open the excel file, rename the sheets, save and close it. Now we can start coding to open and rename the first excel sheet from "Sheet1" to "NewName".
1. Create a file ExcelRename.vbs and paste the below VBScript Code
':: How to rename Excel worksheet from VBScript '---------------------------------------------- 'create the excel object Set objExcel = CreateObject("Excel.Application") 'view the excel program and file, set to false to hide the whole process objExcel.Visible = True 'turn off screen alerts objExcel.DisplayAlerts = False 'open an excel file (make sure to change the location) .xls for 2003 or earlier Set objWorkbook = objExcel.Workbooks.Open("C:\Viji\Test.xlsx") 'Use objWorkbook.Worksheets.count to get the count of sheets 'Get the first sheet Set objWorksheet = objWorkbook.Worksheets(1) 'Rename the sheet objWorksheet.Name = "NewName" 'save the existing excel file. use SaveAs to save it as something else objWorkbook.Save 'close the workbook objWorkbook.Close 'exit the excel program objExcel.Quit 'release objects Set objExcel = Nothing Set objWorkbook = Nothing
2. Double click ExcelRename.vbs to execute. The sheet has been renamed from "Sheet1" to "NewName"
After rename |
It's so simple !!!! Happy Coding.