Code VBA Preferences menu

Preference settings

The following sections explain how you can make Code VBA match the way you work.

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.

What should inserted code look like

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

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

By changing two preferences, removing the check for 'Named Arguments' and 'Declare Variables', we can produce totally different code:

str = Left()

Named Arguments (Explicit)

In the above example the preference 'Named Arguments' determines if the code String:= and Length:= gets inserted

Explicit Arguments are useful to clarify what a procedure argument is used for. It makes the code self documenting.

Declare Variables

In the first example the preference 'Declare Variables' was checked. All arguments of the procedure, including the return argument get a variable declared of the type and using the name of the argument.

Actually, the above shows directly an exception, in that no variable was declared for the argument Length. We made some arbitrary decisions here which will somtimes work out ok and sometimes not.

You will notice that the return variable is named after the function.

Another feature of code insertion is that it attempts to prevent insertion of too many variables by looking at the code before the current line.

Click this Start demo screencast to see how both variables for the arguments of the Left function are not declaredlimiting variables:

Dim strName As String
If Left(String:=strName, Length:= ) Then
    
End If

Would there have been more strings, then only a prefix gets inserted as the insertion has no reason to assume it is one or the other variable. From the prefix then intellisense can be used to pick up the intended variable

Dim strName As String
Dim strName1 As String
If Left(String:=str, Length:= ) Then
    
End If

Another thing worth noting is the insertion of a line after the variable. The idea is that you need to assign a value.

Variables on Separate Lines

The above example assumes the preference 'Variables on Separate Lines' is checked. If unchecked all variables will appear on a single line, see below.

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

Use short syntax for Item in Collection

When checked, the result is:

Set wb = Application.Workbooks()

Alternatively, the method Item is explicit.

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
...

Special areas of code you may or may not be interested in

Not every user is interested in the math or financial functions. By unchecking 'Show VBA Financial' - and the others - the number of menu items under Code VBA » VBA becomes more manageable.

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.

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.