Preference settings

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

What should inserted code look like

When code VB 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 'Explicit Arguments' and 'Declare Variables', we can produce totally different code:

str = Left()

Explicit Arguments

In the above example the preference 'Explicit 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 VB Financial' - and the others - the number of menu items under Code VB » 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.