renaming a newly added worksheet in excel with VB.

  • 8 years ago

    Hi,


    I would like to add a new name to freshly added worksheet in an excel workbook with VB.NET 2005...  I have already used
    excelWorksheet.Name to name the current worksheet.  But I will need to add more sheets and I would like to use the same name on each sheet and concatenate a number on the end of the name.  So I can navigate though my workbook and place data on the correct sheets.


    Any suggestion?
    Thank you



  • 8 years ago
    Why not name it as you are creating the worksheet?
  • 8 years ago
    thank you...   i did, at least for the first sheet, after then as sheets are added they are numbered.
  • 8 years ago

    For one application, I used a pre-defined template worksheet and copied it each time a needed a new sheet.
    This may point you in the right direction....


    Global oXL As Excel.application
    Global oWB As Excel.Workbook
    Global oTemplate As Excel.Workbook
    Global oSheet As Excel.Worksheet


    With oWB
        .Sheets("Template").Copy After:=.Sheets(.Sheets.count)     'copy from the "template"
        .Sheets("Template (2)").name = shtName     'rename the sheet
        Set oSheet = .Sheets(shtName)     'make this the active sheet
    End With

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perl - The only language that looks the same before and after RSA encryption.” - Keith Bostic