3.13 How To Clean Your Code
3.13 How To Clean Your Code
3.13 How To Clean Your Code
?myVar
You can also type in a statement and it is executed when you press enter:
ActiveCell.Value = 123
You can also put statements in your code that write to the Immediate window:
http://appspro.com/Utilities/CodeCleaner.htm
Basically, the code cleaners store the code in an ASCII file, delete the module, and then recreate
it with the code stored in the ASCII file. Code that has not been cleaned has been know to be
unstable and cause crashes.
Option Explicit
The above statement insures that all variables that you use in the module must be declared with a
Dim statement. This insures that you do not misspell a variable's name and accidentally create a
new variable.
The above statement makes any text comparison in the module case insensitive.
The above statement prevents subroutines and functions in a module from being visible to the
macro list available from the Tools menu. They can however be referenced by other subroutines
and functions in other modules in the workbook.
30
Andrew Baker has created a free program called a workbook rebuilder available at his site:
http://www.vbusers.com
http://www.vbusers.com/downloads/download.asp#item2
In the Project Explorer, click on the project line, the one with the name of the
workbook.
Change the name to the project to a more descriptive name. Spaces are not
allowed. Use underscores instead of spaces.
To dock the Explorer window, move it left until the thick gray line around it turns into a thin
dotted one. It should attach to the left side of the screen.
To dock the properties window move it left and down almost until it disappears off the lower left
part of your screen. At this point the gray line should change again into a dotted one. Let go and,
hopefully, it should return to normal. If it does not on the first try just double click on the
properties window blue menu bar and try again… and again... and again...
The key thing is to watch the window outline as you drag. The thick gray outline will leave the
window floating in the middle of the screen, on top of any undocked windows. A thin dotted
outline will dock the window at an edge or against another docked window.
However, the final docking place is not quite as haphazard as it might seem. If you drag the thin
outline left and right across the bottom of the screen (keeping it low enough to avoid the thick
outline), you will see its shape go through a number of transitions that indicate how it will dock.
It is best to have a maximized code module open while you do this. Otherwise, the gray border is
difficult to see against the gray window background.
31
A slightly taller outline indicates that it will dock against the left or right edge of the screen or
left or right edge of another docked window. A slightly flatter short outline indicates it will dock
under another docked window or against the bottom of the screen. If you drag the outline really
low, it will widen and indicate that it will cover the entire bottom of the screen. These changes
are fairly subtle, so you really have to look carefully. In Excel 2000, these changes are more
exaggerated and easier to see,
http://support.microsoft.com/support/kb/articles/q148/2/40.asp
That informs you about an MS Application Note "WE1277:XL7:Visual Basic Equivalents for
Lotus Macro Commands". Click on the WE1277.EXE to download this file. When you
download an run it, It creates a word documentation that you can then read.
32
then have your code modify the cells. Please see the topics on Application.InputBox or
InputBox for examples of how to use these features.
33