Microsoft Office Tutorials and References
In Depth Information
Introducing the Visual Basic Editor
You can consult the VBA Help system to identify various properties, but using the macro recorder
is often more efficient if you don’t know exactly what you’re looking for. After you identify what
you need, you can check the Help system for details.
You can use the Excel Options dialog box to change the UserName property back to
what it was. Or, you can make the change by using VBA. Just edit the code in the
recorded macro (replace the name quotes with the original username). Then, move the
cursor anywhere within the Macro1 procedure and choose Run➜Run Sub/UserForm (or
press F5) to execute the macro. Executing the macro changes the UserName property.
Copying VBA code
This section has covered entering code directly and recording your actions to generate VBA
code. The final method of getting code into a VBA module is to copy it from another module. For
example, you may have written a custom function for one project that would also be useful in
your current project. Rather than reenter the code, you can open the workbook, activate the
module, and use the normal Clipboard copy-and-paste procedures to copy it into your current
You also can copy VBA code from other sources. For example, you may find a listing on a Web
page or in a newsgroup. In such a case, you can select the text in your browser (or newsreader),
copy it to the Clipboard, and then paste it into a module.
Saving your project
As with any application, you should save your work frequently while working in the VB Editor. To
do so, use File
Save xxxx (where xxxx is the name of the active workbook), press Ctrl+S, or click
the Save button on the standard toolbar.
When you save your project, you actually save your Excel workbook. By the same
token, if you save your workbook in Excel, you also save the changes made in the
workbook’s VB project.
The VB Editor does not have a Save As command. If you save a workbook for the first time from the
VB Editor, you are presented with Excel’s standard Save As dialog box. If you want to save your
project with a different name, you need to activate Excel and use Excel’s Save As command.