30.04.2017 Views

4523756273

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

42<br />

Part II: How VBA Works with Excel<br />

You can remove VBA modules, but there is no way to remove the other code<br />

modules — those for the Sheet objects or ThisWorkbook.<br />

Exporting and importing objects<br />

Every object in a VBA project can be saved to a separate file. Saving an individual<br />

object in a project is known as exporting. It stands to reason that you<br />

can also import objects to a project. Exporting and importing objects might<br />

be useful if you want to use a particular object (such as a VBA module or a<br />

UserForm) in a different project.<br />

Follow these steps to export an object:<br />

1. Select an object in the Project window.<br />

2. Choose File➪Export File or press Ctrl+E.<br />

You get a dialog box that asks for a filename. Note that the object<br />

remains in the project; only a copy of it is exported.<br />

Importing a file to a project goes like this:<br />

1. Select the project’s name in the Explorer window.<br />

2. Choose File➪Import File or press Ctrl+M.<br />

You get a dialog box that asks for a file. Locate the file and click Open.<br />

You should only import a file if the file was exported by using the<br />

File➪Export File command.<br />

Working with a Code Window<br />

As you become proficient with VBA, you spend lots of time working in Code<br />

windows. Macros that you record are stored in a module, and you can type<br />

VBA code directly into a VBA module.<br />

Minimizing and maximizing windows<br />

If you have several projects open, the VBE may have lots of Code windows at<br />

any given time. Figure 3-3 shows an example of what I mean.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!