Excel Worksheet Naming problem

T

Terry Fox

I'm having trouble naming a new worksheet I added to an excel workbook.

Here is the basic code I'm using to open a new workbook and create the new
worksheet, but I can't figure out for the life of me how to name this new
worksheet after creating it. It's probably pretty simple, but I just can't
seem to get it, any help would be appreicated.

Dim ObjExcel As Excel.Application
Set ObjExcel = New Excel.Application
ObjExcel.Worksheets.Add

Terry
 
K

Kim Mitchell

The code that you have may be OK if you are in an application other than
Excel. If you are coding in Excel, you are overdoing it. You don't need
the first 2 lines and the first part of the third. All you need it:

Workbooks.Add ' If you don't have a workbook, this creates one.
Worksheets.Add ' Add a worksheet
ActiveSheet.Name = "Any Name" ' Name a worksheet.

Kim
 
T

Terry Fox

Sorry about that, I should have explained better.
I'm actually using VB6 to pull data from and access database, and
I'm creating a report in excel with the data accumulated.
So I'm trying to open up an existing excel workbook, and add a new worksheet
to the workbook, and then rename it, based upon the quarter that the report
is running for.

Terry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top