Visual Basic for Applications Tips #32



----------------------------------------------

TipWorld - http://www.tipworld.com
The Internet's #1 Source for Computer Tips, News, and Gossip

Proudly presents:
Visual Basic for Applications

----------------------------------------------


*1. RETURNING A FORM'S NAME                 
        
In our last tip, we showed you how to use the Forms.Count 
tatement to return the number of loaded forms (in the Immediate 
window). If you want to identify your forms, open the Immediate 
window and run the statement 

? Forms(0).Name 

This statement will return the name of the first form in the 
collection. If there's more than one form, replace the index 
value with the value 1 and rerun the statement. Continue in this 
manner until you've identified all the loaded forms.


*2. UNREGISTERING A DLL                 
        
Earlier in the year we talked about Regsvr32.exe--a utility for 
registering DLLs. Unfortunately, sometimes the utility can't 
register the DLL because an existing version of the DLL is still 
registered. When you need to determine if a DLL is already 
registered and where, you can use Regedit.exe's Find feature. 
It's probably the most efficient method. 

To find a registered DLL, choose Run from the Start menu and enter 

regedit 

Once Windows launches this utility, choose Find from the Edit 
menu and enter the name of the DLL you're trying to find. Then, 
click Find Next. If the DLL is registered, the Find feature will 
take you directly to the appropriate key.


*3. INSERT WHITESPACE                 
        
You can use white space to make your code more readable. The most 
logical place for inserting white space (a blank line) is at the 
end of a task. Some developers enter blank lines only between sub 
and functions. Others enter a blank line before or after comments. 
Still others also separate each section of code with a blank line 
(by section, we mean task). 

Where to insert blank lines is up to you, but doing so can improve 
the readability of your code. Eventually, you'll be able to find 
sections at a glance by skimming through the blank lines.


*4. PROTECTING GLOBAL VARIABLES                 
        
It's easy to make a variable available to your entire 
procedure--simply declare the variable as a public variable. You 
should do so with caution. Why? Because not only is your variable 
available to all procedures, it's also updateable by all 
procedures. When one procedure updates a public variable, that 
variable is updated for all the procedures--whether or not you 
meant to do so. So, if your strategy's not solid, one procedure 
could affect another in a negative way. 

An easy way to avoid this problem is to copy the public variable 
to a local variable (at the procedure level). Doing so will 
protect the variable--at the local level now--from further 
updates. Any updates will affect only the public variable, not 
the local copy. 

This tip is for the odd times when you run into this 
situation--not for every public variable you write. Of course, 
the best solution is to avoid the public variable altogether if 
updating it in one procedure has a negative effect on another procedure.


*5. NON-MICROSOFT VBA APPLICATIONS                 
        
VBA isn't just for Microsoft products anymore. Several 
applications now license VBA, so if you need more power than 
Office provides, you won't need to learn a new language if you 
use one of the following applications: 

Visio--graphics package 
Corel WordPerfect Office 2000--word processing, spreadsheet, 
    and database suite 
Corel Draw 9--graphics package 
AutoCAD--design application 
M.Y.O.B. Accounting--accounting package for small businesses 
Micrografx iGrafx series--business graphics 
OmniTrader--securities tracking and analysis


*6. ONE CLICK OPENS THE VISUAL BASIC EDITOR                 
        
You probably press Alt-F11 to open the Visual Basic Editor, but 
there's an easier way. Most Office VBA applications offer the 
Visual Basic Editor button--you'll find it on the Visual Basic 
toolbar. If you use the editor a lot, you should consider 
copying this button to one or more of the standard toolbars. That 
way, you can open the editor at any time with one quick click.


*7. COPYING TOOLBAR BUTTONS                 
        
In our last tip, we told you about the Visual Basic Editor button,
a toolbar button that you can copy to the standard toolbars for 
quick, one-click access to the Visual Basic Editor. An easy way 
to copy any toolbar button is to hold down the Alt button and 
drag the button from one toolbar to another. That means you can 
display the Visual Basic toolbar, hold down the Alt key, drag 
the Visual Basic Editor button to the Standard toolbar, and then 
close the Visual Basic toolbar. It really is that easy!


*8. STEALING FROM HELP                 
        
The Help system is full of code fragments that you can put to 
good use as is or with a few minor adjustments. So before you try 
to reinvent the wheel, do a quick search in the VBA Help system 
for any code that you can use as the basis for your current task. 
When you find something you can put to use, highlight those lines 
with your mouse, right-click the selection, and choose Copy (or 
press Ctrl-C). Then, switch to a module in the Visual Basic 
Editor and click the Paste button on the Standard toolbar, or 
press Ctrl-V.


*9. INSTALLING ALL THE HELP FILES                 
        
We mentioned in our last tip that the Help system is full of code 
that you can cut and paste to your modules. However, unless you 
installed a complete set of VBA Help files, those Help files may 
not be available to you. If you're working with Office, the 
Setup program installs some but not all of the VBA Help files. 
If you'd like all of the Help files, run Setup again, but this 
time choose the Custom install. Then, open each application, 
select the Help And Sample Files option, and then click the 
Change option. In the resulting dialog box, select Online Help 
For Visual Basic and click OK.


*10. INSTALLING OUTLOOK 97 HELP FILES                 
        
If you took our last tip to heart and installed the VBA Help 
files, and you're using Office 97, you didn't install Outlook's 
VBA Help files. If you need these files, you'll have to copy 
them from the Valupack\Morehelp folder on your Office CD. 
Specifically, you're looking for Vbaoutl8.hlp. Once you find it 
in the Valupack folder, be sure to copy it to the Office 
97 folder.
