• Excel VBA Naming Conventions… (2000 SR-1)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Excel VBA Naming Conventions… (2000 SR-1)

    Author
    Topic
    #395146

    Does anyone have a list (or link to a list) of the proper standard naming conventions for Excel VBA programming? TIA

    Viewing 1 reply thread
    Author
    Replies
    • #730265

      Here’s the Reddick conventions.

      • #730276

        Thanks John… thankyou

        I appreciate that, but that list I know… I’m looking for generally followed naming conventions specifically for Excel Objects… such as prefixes to use when declaring Excel Objects like worksheets and ranges, etc…… For example “Dim someName as Workbook” … Should that object variable name be given a certain prefix? ….and if so, is there a list of such prefixes?

        • #730287

          I don’t have it with me right now, but I think that John Walkenbach does in his book MS Excel Power Programming with VBA. I can check tomorrow.

          • #730293

            Thanks!… I can wait… (I’ve been wondering this for agessssss…) smile

            • #730333

              He suggests prefixing a lower case:
              b for Boolean
              i for integer
              l for Long
              s for Single
              d for Double
              c for Currency
              dt for Date/Time
              str for String
              obj for Object
              v for Variant
              u for User-defined

              His XL2000 book does not really list anything for the XL objects (as was your original question). He is also not consistent in his use of the conventions. He suggests declaring the variables, but frequently does not do this in his code.

              Steve

            • #730343

              Hmmm… Well thanks anyway Steve… cheers

              I personally use…
              bln for Boolean
              int for Integer
              lng for Long
              sng for Single
              dbl for Double
              etc…
              I think that’s pretty standard…

              I guess it doesn’t really matter as long as the prefixes are intuitive and consistent… I was just curious because I’m trying to get better at Excel VBA, I don’t have a book (yet), Excel 2000 Help SUCKS (half the time it doesn’t even show the declarations in the examples…), and I know there are experts on here whose opinions I trust and respect… Every time I declare a worksheet or a range or whatever, I think… “Now what should I be using here… sht for Worksheet… wrksht…. or what??” … I’m just particular (or should I say peculiar) like that… laugh

            • #730347

              I just make up my own prefixes:

              Object Prefix
              Chart cht
              Dialog dlg
              PivotTable pvt
              QueryTable qtb
              Range rng
              Series ser
              Shape shp
              Sheet sht
              Workbook wbk
              Worksheet wsh

              But I reserve the right to deviate from this. Depends on my mood, the phase of the moon, etc. grin

            • #730395

              Thanks Hans… This is a great reference for me as I get used to it… cheers

            • #730396

              Thanks Hans… This is a great reference for me as I get used to it… cheers

            • #730348

              I just make up my own prefixes:

              Object Prefix
              Chart cht
              Dialog dlg
              PivotTable pvt
              QueryTable qtb
              Range rng
              Series ser
              Shape shp
              Sheet sht
              Workbook wbk
              Worksheet wsh

              But I reserve the right to deviate from this. Depends on my mood, the phase of the moon, etc. grin

            • #730362

              Here are 2 KB articles from Microsoft:

              http://support.microsoft.com/default.aspx?…kb;en-us;110264%5B/url%5D
              http://support.microsoft.com/default.aspx?…kb;en-us;173738%5B/url%5D

              Though these don’t answer your question either.

              I agree with Hans. I try to use particular ones, though i don’t hold myself to them (I am not anal enough to stop myself from being sloppy)
              Steve

            • #730397

              laugh Well I TRY to keep myself from being sloppy… not that it always works…
              Thanks for the articles Steve!

            • #730398

              laugh Well I TRY to keep myself from being sloppy… not that it always works…
              Thanks for the articles Steve!

            • #730363

              Here are 2 KB articles from Microsoft:

              http://support.microsoft.com/default.aspx?…kb;en-us;110264%5B/url%5D
              http://support.microsoft.com/default.aspx?…kb;en-us;173738%5B/url%5D

              Though these don’t answer your question either.

              I agree with Hans. I try to use particular ones, though i don’t hold myself to them (I am not anal enough to stop myself from being sloppy)
              Steve

            • #730510

              I try to use prefixes as much as I can force myself to smile.

              I started off with single letter ones and now mix single and three letter prefixes.

              What you use is not very important, as long as you try to stick to it.

              For XL objects I tend to be lazy, I just use o, as in
              Dim oRange as Range

            • #730511

              I try to use prefixes as much as I can force myself to smile.

              I started off with single letter ones and now mix single and three letter prefixes.

              What you use is not very important, as long as you try to stick to it.

              For XL objects I tend to be lazy, I just use o, as in
              Dim oRange as Range

            • #730344

              Hmmm… Well thanks anyway Steve… cheers

              I personally use…
              bln for Boolean
              int for Integer
              lng for Long
              sng for Single
              dbl for Double
              etc…
              I think that’s pretty standard…

              I guess it doesn’t really matter as long as the prefixes are intuitive and consistent… I was just curious because I’m trying to get better at Excel VBA, I don’t have a book (yet), Excel 2000 Help SUCKS (half the time it doesn’t even show the declarations in the examples…), and I know there are experts on here whose opinions I trust and respect… Every time I declare a worksheet or a range or whatever, I think… “Now what should I be using here… sht for Worksheet… wrksht…. or what??” … I’m just particular (or should I say peculiar) like that… laugh

            • #730334

              He suggests prefixing a lower case:
              b for Boolean
              i for integer
              l for Long
              s for Single
              d for Double
              c for Currency
              dt for Date/Time
              str for String
              obj for Object
              v for Variant
              u for User-defined

              His XL2000 book does not really list anything for the XL objects (as was your original question). He is also not consistent in his use of the conventions. He suggests declaring the variables, but frequently does not do this in his code.

              Steve

          • #730294

            Thanks!… I can wait… (I’ve been wondering this for agessssss…) smile

        • #730288

          I don’t have it with me right now, but I think that John Walkenbach does in his book MS Excel Power Programming with VBA. I can check tomorrow.

      • #730277

        Thanks John… thankyou

        I appreciate that, but that list I know… I’m looking for generally followed naming conventions specifically for Excel Objects… such as prefixes to use when declaring Excel Objects like worksheets and ranges, etc…… For example “Dim someName as Workbook” … Should that object variable name be given a certain prefix? ….and if so, is there a list of such prefixes?

    • #730266

      Here’s the Reddick conventions.

    Viewing 1 reply thread
    Reply To: Excel VBA Naming Conventions… (2000 SR-1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: