Microsoft Office Tutorials and References
In Depth Information
Working with Code Windows
Removing a VBA module
If you need to remove a VBA module, a class module, or a UserForm from a project, select the
module’s name in the Project Explorer window and choose File➜Remove xxx (where xxx is the
name of the module). Or you can right-click the module’s name and choose Remove xxx from the
shortcut menu. You’re asked whether you want to export the module before removing it. (See
the next section for details.)
You can’t remove code modules associated with the workbook (the ThisWorkbook code
module) or with a sheet (for example, the Sheet1 code module).
Exporting and importing objects
Except for those listed under the References node, you can save every object in a project to a
separate file. Saving an individual object in a project is called exporting. It stands to reason that
you can also import objects into a project. Exporting and importing objects might be useful if you
want to use a particular object (such as a VBA module or a UserForm) in a different project.
To export an object, select it in the Project Explorer window and choose File➜Export File. You
get a dialog box that asks for a filename. Note that the object remains in the project. (Only a
copy of it is exported.) If you export a UserForm object, any code associated with the UserForm
is also exported.
To import a file into a project, select the project’s name in the Project Explorer window and
choose File➜Import File. You get a dialog box that asks for a file. You can import only a file that
has been exported by choosing the File➜Export File command.
If you want to copy a module or UserForm to another project, you don’t need to export
and then import the object. Make sure that both projects are open; then simply activate
the Project Explorer and drag the object from one project to the other. The original
module or UserForm remains, and a copy is added to the other project.
Working with Code Windows
When you become proficient with VBA, you’ll be spending lots of time working in code windows.
Each object in a project has an associated code window. To summarize, these objects can be
h The workbook itself ( ThisWorkbook in the Project Explorer window)
h A worksheet or chart sheet in a workbook (for example, Sheet1 or Chart1 in the
Project Explorer window)
h A VBA module
h A class module (a special type of module that lets you create new object classes)
h A UserForm
Search JabSto ::

Custom Search