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.

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=
Format=Formatted
  • 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
...