WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Excel
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Rename Existing Excel Worksheet

 Keywords:  Rename Existing Excel Worksheet XLS XLSX

Question:

I would like to rename an existing worksheet in and excel file and save it. Any ideas please?

Answer:

Here is some sample code to get you started:
sheetname = 'My New Sheet Name'
ExcelFileName = "D:\temp\DATA\Excel-Random-Numbers-Test.xlsx"

;Open Excel application Object
Excel = ObjectCreate("Excel.Application")
Excel.visible = @TRUE

; Open Existing Workbook
Excel.Workbooks.Open(ExcelFileName)

; Rename First Worksheet
Excel.Workbooks(1).Worksheets(1).name  = sheetname
Message('Done', 'Renaming first worksheet')

; Close Object Handles
Excel = 0

Article ID:   W18112
Filename:   Rename Existing Excel Worksheet .txt
File Created: 2009:06:24:11:29:18
Last Updated: 2009:06:24:11:29:18