The following sections explain how you can make Code VBA match the way you work.
- Show Tooltip on MouseHover
- Let Code VBA features match your VBA experience level
- Customizing the Excel VBA menu
- Customize the Code VBA toolbar
- Determine what the inserted code should look like
- Enable (or disable) areas you are (not) interested in
- Change variable prefixes and names of return variables
|Alt-CP | Menu: Code VBA » Preferences »|
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'.
|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
|Alt-CVSL | Menu: Code VBA » VBA » String » 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
Length:= gets inserted
Explicit Arguments are useful to clarify what a procedure argument is used for. It makes the code self documenting.
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 to see how both variables for the arguments of the Left function are not declared:
- As there is only one string variable before current line, the insertion process decides that strName is the likely candidate for the
String:=argument - so it refrains from declaring strString.
- Considering the function is used inside
If Thenthere is no use for declaring the return variable
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.
|Alt-CPC | Menu: Code VBA » Preferences » Change prefixes|
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
|Alt-CPR | Menu: Code VBA » Preferences » 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
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=Formattedmeans '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.