Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm using Excel 2003; it appears that the max length of a sheet-name is 31 characters. So far, so good.

    I'm using VBA code to create a chart on my sheet; here's what I use:

    ASh = ActiveSheet.Name
    Charts.Add
    ActiveChart.Location Where:=xlLocationAsObject, Name:=ASh

    When the string length of "Ash" is 31, I get an error in the last line of code... Am I missing something?

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='ErikJan' post='765239' date='13-Mar-2009 15:18']When the string length of "Ash" is 31, I get an error in the last line of code... Am I missing something? [/quote]
    You're not missing anything, there appears to be a bug in Excel for this particular method. 30 characters for a sheet name is OK, 31 isn't.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    5 Star Lounger
    Join Date
    Aug 2004
    Location
    Connecticut, USA
    Posts
    816
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's not a bug, it's a special feature. (careful you don't slip in the sarcasm, it tends to drip)

    You could use a little work around:
    Code:
    Dim ASh As String, cht As Chart, strSheetName As String
    
    	strSheetName = ActiveSheet.Name
    	ActiveSheet.Name = Left(ActiveSheet.Name, 30)
    	ASh = ActiveSheet.Name
    	Set cht = Charts.Add
    	Set cht = cht.Location(Where:=xlLocationAsObject, Name:=ASh)
    	ActiveSheet.Name = strSheetName
    You'll run into an error you have a sheet with 30 characters that matches your 31 character sheet's first 30 character.

Posting Permissions

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