Answered Maximum Sheet Name Length Constant

  • Wednesday, August 01, 2012 11:29 PM
     
     
    Is there a property or constant available in VBA that can tell me what the maximum allowed length of a sheet name is? I want to set a sheet name programmatically based on user input and I need to make sure the name provided does not exceed the limit. I found many code examples where this is hard-set as 31 characters, but I would like to avoid doing so if there is a constant or property that can provide me this information in case the limit is increased in a future version of Excel.
    • Edited by JadrienD Wednesday, August 01, 2012 11:30 PM
    •  

All Replies

  • Thursday, August 02, 2012 5:16 AM
     
     Answered

    As far as I know, there is no such property. You could create such a constant yourself at the top of a module:

    Public Const MaxSheetNameLength = 31

    and refer to the constant in your code.

    If it changes in the future, you'll only have to change the value of the constant.


    Regards, Hans Vogelaar

    • Marked As Answer by JadrienD Friday, August 03, 2012 3:38 AM
    •  
  • Friday, August 03, 2012 3:38 AM
     
     
    I figured there wasn't and what you suggested is what I already did. Thanks Hans.