Attribute VB_Name = "modVBANamingConventions" ' +------------------------------------------------------------------------------------------+ ' | __ __ _ _ _ | ' | ___ \ \/ / ___ ___ | | ___ ___ __| |(_) _ __ __ _ ___ ___ _ __ ___ | ' | / _ \ \ / / __|/ _ \| | / __|/ _ \ / _` || || '_ \ / _` | / __|/ _ \ | '_ ` _ \ | ' | | __/ / \| (__| __/| || (__| (_) || (_| || || | | || (_| | _| (__| (_) || | | | | | | ' | \___|/_/\_\\___|\___||_| \___|\___/ \__,_||_||_| |_| \__, |(_)\___|\___/ |_| |_| |_| | ' | |___/ | ' | | ' +------------------------------------------------------------------------------------------+ ' | Title : modVBANamingConventions | ' | Author : Thomas James Rowe, excelcoding.com | ' | Version : 1.0 | ' | Release Date : 25/01/2022 | ' | Details : | ' | VBA Naming Conventions. | ' +------------------------------------------------------------------------------------------+ ' 1. Excel VBA Naming Conventions ' 1.1 Why Use Naming Conventions ? ' Using naming conventions… ' • Makes your code easier to follow and understand. ' • Makes your code easier to debug. ' • Makes your code more consistent across different projects. ' For example, without a naming convention a variable can be defined as ‘MyVariable’ in your code there is ' no way of telling what data type the variable is i.e. Boolean, Long, String etc. However, if you prefix ' the variable with an abbreviation for the data type for instance ‘str’ for String the variable is defined ' as strMyVariable so you know when it appears in the code that it is a String Variable. ' 1.2 Variable Naming Conventions ' +--------------+--------+--------------------+ ' | Data Type | Prefix | Example Definition | ' +--------------+--------+--------------------+ ' | Boolean | bln | blnTrueOrFalse | ' +--------------+--------+--------------------+ ' | Byte | byt | bytMyByte | ' +--------------+--------+--------------------+ ' | Currency | cur | curMyCurrency | ' +--------------+--------+--------------------+ ' | Date | dte | dteMyDate | ' +--------------+--------+--------------------+ ' | Decimal | dec | decMyDecimal | ' +--------------+--------+--------------------+ ' | Double | dou | douMyDouble | ' +--------------+--------+--------------------+ ' | Integer | int | intMyInteger | ' +--------------+--------+--------------------+ ' | Long | lng | lngMyLong | ' +--------------+--------+--------------------+ ' | LongLong | lnglng | lnglngMyLongLong | ' +--------------+--------+--------------------+ ' | LongPtr | lngptr | lngptrMyLongPtr | ' +--------------+--------+--------------------+ ' | Object | obj | objMyObject | ' +--------------+--------+--------------------+ ' | Single | sin | sinMySingle | ' +--------------+--------+--------------------+ ' | String | str | strMyString | ' +--------------+--------+--------------------+ ' | Variant | vnt | vntMyVariant | ' +--------------+--------+--------------------+ ' | User-defined | usd | usdMyUserDefined | ' +--------------+--------+--------------------+ ' 1.2.1 Microsoft Data Type Summary ' https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/data-type-summary ' 1.2.2 Private and Public Scope ' If you also want to identify the Private and Public scope of a variable… ' Private – pri_ (pri_intMyPrivateInteger) ' Public – pub_ (pub_intMyPublicInteger) ' 1.3 Standard Control Naming Conventions ' +---------------+--------+--------------------+ ' | Control | Prefix | Example Definition | ' +---------------+--------+--------------------+ ' | ComboBox | cbo | cboMyComboBox | ' +---------------+--------+--------------------+ ' | CommandButton | cmd | cmdMyCommandButton | ' +---------------+--------+--------------------+ ' | CheckBox | chk | chkMyCheckBox | ' +---------------+--------+--------------------+ ' | Frame | fra | fraMyFrame | ' +---------------+--------+--------------------+ ' | Image | img | imgMyImage | ' +---------------+--------+--------------------+ ' | Label | lbl | lblMyLabel | ' +---------------+--------+--------------------+ ' | ListBox | lst | lstMyListBox | ' +---------------+--------+--------------------+ ' | ListView | lvw | lvwMyListView | ' +---------------+--------+--------------------+ ' | OptionButton | opt | optMyOptionButton | ' +---------------+--------+--------------------+ ' | ProgressBar | pbr | pbrMyProgressBar | ' +---------------+--------+--------------------+ ' | MultiPage | mpg | mpgMyMultiPage | ' +---------------+--------+--------------------+ ' | ScrollBar | scl | sclMyScrollBar | ' +---------------+--------+--------------------+ ' | Slider | slr | slrMySlider | ' +---------------+--------+--------------------+ ' | SpinButton | spn | spnMySpinButton | ' +---------------+--------+--------------------+ ' | TabStrip | tab | tabMyTabStrip | ' +---------------+--------+--------------------+ ' | TextBox | txt | txtTextBox | ' +---------------+--------+--------------------+ ' | ToggleButton | tog | togMyToggleButton | ' +---------------+--------+--------------------+ ' | WebBrowser | web | webMyWebBrowser | ' +---------------+--------+--------------------+ ' 1.4 Other Naming Conventions ' 1.4.1 Arrays ' Array – arr (arrMyArray) ' 1.4.2 Constants ' It is recommended that constants are defined in uppercase (MYCONSTANT). ' 1.4.3 UserForm ' UserForm – frm (frmMyUserForm) ' 1.4.4 Modules ' Class Module – cls (clsMyClassModule) ' Module – mod (modMyModule) ' 1.4.5 Workbooks and Worksheets ' Workbook – wb (wbMyWorkbook) ' Worksheet – ws (wsMyWorkSheet)