Results 1 to 20 of 20

Thread: [RESOLVED] Renaming Worksheets

Hybrid View

  1. #1
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Renaming Worksheets

    This might give you some ideas

    VB Code:
    1. Dim oExcel As Excel.Application
    2.     Dim oBook As Excel.Workbook
    3.     Dim oSheet As Excel.Worksheet
    4.    
    5.     Set oExcel = New Excel.Application
    6.     Set oBook = oExcel.Workbooks.Open("C:\projects\testing.xls")
    7.     oExcel.Visible = True
    8.    
    9.     For Each oSheet In oBook.Worksheets
    10.         'assumes cell A23 is a valid date
    11.         'The Sheet Name cannot contain the characters \ / ? * [ ]
    12.         oSheet.Name = Format$(oSheet.Cells(23, 1), "dd-MMM-yyyy")
    13.     Next
    14.    
    15.     oBook.Close True
    16.     Set oBook = Nothing
    17.    
    18.     oExcel.Quit
    19.     Set oExcel = Nothing

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    28

    Re: Renaming Worksheets

    It doesn't like this line of your code:

    oSheet.Name = Format$(oSheet.Cells(23, 1), "dd-MMM-yyyy")

    It produces the same error messages I've been getting about bad spelling and/or illegal characters in the worksheet name. The weird thing is that it will work if all you want to do is rename the last worksheet because you can use the (sheet.count) code. Excel just seems to reject the automatic renaming of any other sheet except the last one. I know I'm doing something wrong, just don't know what.

    Danno

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width