Preference settings

Code VBA Preferences menu

Every programmer has a personal approach to coding. This page discusses the preferences available in Code VBA to give you optimal support, both by matching your programming style and allowing you to specify when and how support is initiated.

The main task of Code VBA is to assist you effectively in producing code. This requires the coding assistant to

  • Produce code that alligns with your coding style and conventions;
  • Proactively react to the coding context without becoming annoying;
  • Let you select from all relevant continuations without overwhelming you.

Preferences related to the first requirement are discussed under Tailor code generation. Initially, opening menus and builders to create code relevant for the code context is done maximally. The submenu Code VBA IntelliSense allows you to disable specific triggers for ` menus or builders you don't want to open automatically - you may want to initiate them yourself instead. The menu variable assignment has a submenu named 'VBA' which gives a many built-in and custom functions an code snippets. You can alter this under Change Typed IntelliSense. Some parts that systematically belong to a menu are optionally hidden because they are considered not helpful. Such decisions can be changed under

Code VBA IntelliSense

p, f and s trigger corresponding Procedure menu

These menus only get triggered if the cursor is outside a procedure. 's' concludes you intend to make a Sub procedure, and, in addition to the simple code suggest adding scope (Public/Private), the procedure builder with errorhandling and header comment and, in case of Excel and Word, the Macro Recorder and Macro Creator dialog for conveniently starting the procedure from the ribbon. 'f' triggers a Function is intended, select the return type from the submenu. 'p' is interpreted as any of the above, now also including the Property Builder dialog if you are in a class module. Disable if you want to generally start IntelliSense yourself using Shift-Space.

Shift-Space triggers Code VBA IntelliSense

Shift-Space is the default way to activate Code VBA IntelliSense. You may want to disable it and use Control-Space instead if you experience accidental opening of menus frequently caused by not having releases the Shift-key in time.

Control-Space use Code VBA InstelliSense

If checked, the more extensive and context sensitive shortcut menu Code VBA InstelliSense menu replaces the VBE built-in approach.

Disable MS Auto List Members

The IntelliSense built in by Microsoft in the vb editor in many cases is of limited use giving just an alphabetic list of what may be typed. However, you may be so used to it you may really want it anyway. If so, unchecking this preference will make MS Auto List Members available again.

Automatic variable declaration using prefix

If you are familiar with (old school) VB naming conventions you may accelerate declaration of variables by for example typing strName=. With this preference set the variable declaration is automatically added:


Dim strName As String
strName =

Note that to recognize the string as prefix it needs to be a. lowercase and b. optionally followed by Upper case.

'=' trigger IntelliSense menu

the '=' is used both for assigning an object or a value to a variable or object property, or for comparing values. Code VBA can optionally use this '=' as a trigger (e.g. strName=) to open a menu to let you select a value, an expression or even create a new variable or function. It is possible that you find this kind of assistance 'too much', and only want the menu to appear if you ask for it by using Shift-Space. If so, you may selectively turn of the trigger behaviour for the below cases.

Let Variable Assignment '=' trigger IntelliSense

The variable assignment gives a menu with expressions that may be considered good choices given the type of the variable in question. ' As an example, in case of a numeric variable, the menu will show all numeric variables available in the code context. Additionaly, through submenu VBA, it shows all available built-in functions that may provide a suitable value, and so on. Again, if you consider this to interfere with your flow, you can disable this behaviour here and make the menu to appear using Shift-Space.

Let Object Assignment '=' trigger IntelliSense

The Object Assignment menu is less overwhelming than the variable assignment above, and shows all possibilities to set the Object variable, possibly ones you were not aware of. It also conveniently adds the mandatory Set keyword at the beginning of the statement. So even if you decide to turn of the variable assignment trigger, you may well keep this one on.

Let Variable Comparison '=' trigger IntelliSense

The menu opened for Variable Comparison, which typically appears in If statements and Do loops (e.g. If str= Then ), is much more modest. It is limited to variables and object properties of the same type which in most cases is what you need.

Let Object Comparison '=' trigger IntelliSense

The menu opened for Object Comparison is small, only containing variables of the same type or Object or 'Nothing'. It also corrects the '=' to 'Is'. Being so modest there seems little reason to disable this behaviour, unless you really want to only have IntelliSense menus when you explicitly trigger them.

Entering 'Dim' triggers 'Variable' menu

The fast way to declare variables, simply selecting the appropriate type from the menu. Alternatively use Automatic variable declaration using prefix (above.)

Entering 'For' or 'Do' triggers 'Loop' menu

The focus of this menu is to 'For Each' the application's main collection classes (e.g. Excel Sheets). Further down are again variantions of 'Do' and 'For iCounter' loops

Entering 'If' triggers 'lf' menu

The menu gives you access to common (and less common) if statement blocks.

'Sel','Inp', 'Msg', ... open corresponding dialog

On an empty line, entering certain key strings open a special code builder dialog:

  • Sel: Select Case statement builder
  • Inp: Inputbox builder
  • Msg: Messagebox builder
  • Const: Constant builder
  • Enum: Enum builder

We believe these builders are time savers and the chance you intended something different low, but again the behaviour can be deselected.

Change Typed IntelliSense

When activated for a variable assignment, under submenu named 'VBA' gives a plethora of built-in and custom functions an code snippets. For the standard types, string, date, long, etcetera, a text file contains instructions on items to include in the IntelliSense menu, e.g. for Strings lines like:

  • Strings.Left: the VBA Left function
  • VBA\String\modStringFunctions.bas#StringInsert: the StringInsert function contained in the modStringFunctions.bas library file that can be found in the Documents\VBA Code\VBA\String folder.
  • VBA\String\Add Single Quotes.vba: a code fragment (snippet in same folder as above)
  • --- : dividing line to make the menu more organized.

You can thus extend or change the menu to your liking as long as you follow above conventions in placement of fragments and syntax in the file.

The submenus of this preference menu give access to the different submenu types.

Tailor code generation

When code VBA inserts a procedure statement it uses certain decisions which you can change here. As an example, take the function left


Dim strString As String: strString =
Dim strLeft As String
strLeft = Left(String:=strString, Length:= )

Use Named Arguments

Removing the check for 'Named Arguments' produces different code:


str = Left()

Use short syntax for Item in Collection

When checked, the result is:


Set wb = Application.Workbooks()

Alternatively, the method Item is explicit.

Return Variable Names

When a user selects a function, the name of the function is added to the type prefix to construct a name for the variable. If the variable name created is not helpful, you can change it.

As an example, in the code below the return variable for the function Left is constructed from the type prefix str and the function name Left giving the meaningful name strLeft.


Dim strString As String: strString =
Dim strLeft As String
strLeft = Left(String:=strString, Length:=)

If you use a specific function regularly you can change the returned name by adding an appropriate line in the 'returnvarnames.txt' text file which is opened by clicking this preference. Below show too added lines.

  • Environ= means 'don't try to name the variable to Environ'. The reason for not wanting this variable name is this function will return totally different things depending on the argument passed to the function.
  • Format=Formatted means 'use Formatted instead of Format'. The reason for is that Formatted describes what is returned whil Format is to close to the action that produced it.

Prefix variable names

By default we apply the Reddick VBA Naming Convention: for example strID indicates 'this' ID is of type String (not Long). This is usfeful because in many cases the type is not directly clear from the name of a variable, or worse, a mistaken type may cause errors. You can however refrain from prefixes if you don't like them.

Prefix parameter names

Having prefixes is less convenient when for parameters, cluttering the interface. Therefore Code VBA by default does not use prefixes when helping to define parameters of a procedure.

Prefixes for variables

The variable prefixes are stored in a text file. If for a type the prefix is not to your liking, you can add or change it here.

You most benefit of Code VBA if you always use the default, Early Binding. If you check Choose ..., each time you want to use an unreferenced application or library (for the first time) you will be asked if you want Early or Late Binding.

Add Fragment Title

When inserting a code fragment you may want to have your code documented with an extra line filled with the title of the fragment.


'Fill array with files using Dir and FileSpec''
Dim FileSpec As String
...

Show/Hide part of menus

Exluding elements from the Code VBA menus you don't require makes the menus simpler.

Show Active under Object menu

The primary purpose of the Object menu is to support coding with Object Variables. Methods like (Application.)ActiveSheet return objects and are often used, but they are not object variables. You may decide as matter of principle you always want to explicitly name the variables you work with. If so, you can exclude these items from the Object menu by unchecking this preference. Setting corresponding variables is done easily from the Application (e.g. Excel) menu, under Properties.

Hide Set and With for Collection classes

Even though collections are fundamental you will usually not identify them explicitly using an object variable for the collection. Instead, you will have a parent object which gives access to the collection using a property, e.g. the Worksheets property of the Workbook object.

Hide With

Generally, placing multiple statements that concern a selected object in a With block is good practice - for readability and speed. However, when teaching people new to VBA you may well decide to simplify this language construct.

Hide Application Property

Each object has an 'Application' property. You will seldomly use it and it clutters the Properties submenu, therefore by default it is hidden.

The Code VBA main menu (vertical) gives access to menus for the Office Application's that are supported by Code VBA for inter-application automation purposes. This is very relevant for applications such as MS Access, and to a lesser extent Excel. However we believe the likelyhood of automating Word from PowerPoint to be low. We encoded this as

Access=Outlook,Excel,Word,DAO,ADODB
Excel=Outlook
...

meaning that from Access you can automate Outlook, Excel, etcetera but from Excel only Outlook. This way on the Code VBA Outlook appears both in Access and in Excel, while Word can only be automated from MS Access. You can change this as you require.

Show Code Explorer

Show or hide the Code Explorer

In Code Explorer Hide FUNCRES.xlam

Having FUNCRES.xlam in Code Explorer is confusing, clutters it and has no purpose. That is why we chose to hide it.

New procedure skip name inputbox

We have chosen to ask for the procedure name when in the new procedure IntelliSense menu you select a Sub or Function. This is convenient for users not so familiar with VBA syntax or not knowing what to expect. Otherwise, you may be better turning this behaviour off - the cursor is conveniently placed where you can directly enter the name without interuption by the dialog.

Add module on open if none is present

If you want to start coding you usually want to do this in a standard module. Code VBA does this automatically for you if there is not yet such a module present in your document. Disable this feature if you don't like it.

Show Tooltip on MouseHover

This setting determines if a tooltip appears when you hover over a menu item - if info is available. The tooltips are a very useful source of information for classes and procedures you are not familiar with. However if you access the menu mainly using the mouse, the constant appearance of tooltips may get in the way. In that case you may be better of un-checking the preference 'Show Tooltip on MouseHover'.

Tip: F1
Pressing F1 makes a tooltip available that shows the what procedure code will be inserted and a description of the procedure or class - if available. If you see the text hyperlinked you can press F1 again which opend the relevant help page in the browser.

Toolbar Configuration

Different users have different preferences regarding the Code VBA toolbar. You may want to have Icons instead text for the toolbar menus, or hide some. Also, for languages other then English you may decide to change the Alt-key (shortcut).