Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change excel sheet name programmatically

Status
Not open for further replies.

mwheads

Programmer
Apr 24, 2004
38
0
0
ZA
Hi All

Does anybody know the command to change the sheet name.
I have a csv file which i convert to an excel file with the following code but I specifically require the sheet name to be "Sheet1" for sql import purposes

Dim oEx
oEx = CreateObject("Excel.Application")
oEx.workbooks.open("C:\TESTING\Test File.csv")
oEx.DisplayAlerts = False
oEx.activeworkbook.saveas("C:\TESTING\Test File.xls", -4143, , , False, False)

>>>> Is there something I can put here to change the sheet name <<<<< like oEx.Worksheets(1).Name = "Sheet1" ???

oEx.DisplayAlerts = True
oEx.quit()
 
You need to change it before you save it.
Code:
Dim oEx
oEx = CreateObject("Excel.Application")
oEx.workbooks.open("C:\TESTING\Test File.csv")
oEx.DisplayAlerts = False

oEx.Worksheets(1).Name = "Sheet1"

oEx.activeworkbook.saveas("C:\TESTING\Test File.xls", -4143, , , False, False)

oEx.DisplayAlerts = True
oEx.quit()
Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top