Remove A Module

You can remove modules from the Visual Basic Editor rather quickly. As you work within the Visual Basic Editor, you may find that you have modules that you want to remove from a selected project. Typically, you delete modules that contain subroutines and functions that you no longer need for your project.

When you remove a module that contains code for a macro used within Excel, remember that you can no longer access the macro. Also, if you remove a module that contains code referenced by a procedure in another module, including an Excel macro, an error message displays when you run the code in the other module. To avoid error messages, you may want to consider saving the module to another file before you delete it.

When you remove a module, the Visual Basic Editor provides the opportunity to export the module to a file so you can reload it again, either in the same project or a different project. If you do not export the module to a file before deleting it, you cannot restore it later. Even if you do not intend to use the module again, to make sure that you do not cause problems with other procedures or subroutines in the project, again, you should save the module to a file before deleting it. After you ensure that everything works, you can delete the exported file. When you export the module to a file, the Visual Basic Editor saves this module in a .bas file that you can import back into a project again at any time.

When you delete macros within Excel, Excel removes the corresponding VBA subroutine code. If the only code contained in the VBA module is the Excel macro, Excel removes the entire module.

REMOVE A MODULE

File | Edit View Insert Format Debug Run tools Add-Ins Window Help i m m ff <g 3? 10

REMOVE A MODULE

File | Edit View Insert Format Debug Run tools Add-Ins Window Help i m m ff <g 3? 10

31 File Edit View Insert Format lools Data Window Help

—D In the Project Explorer, click to highlight the module that you want to remove.

■ If the Project Explorer is not displayed, you can summon it by clicking View O Project Explorer.

Click File O Remove ModuleName where Module Name is the name of the selected module.

■ The Remove command always contains the name of the selected module.

31 File Edit View Insert Format lools Data Window Help

January

February

March April

June

July

August

September

October

November

Office Expenses

Advertising

Rent

1 I Options I

command out of this dialog be

KSheet1 i Sheet2 / 5heet3 /

Selected command:

Description | Modify Se

■ The Visual Basic Editor displays a message to verify the delete selection.

Click Yes to save the module to a file.

■ If you click No, the Visual Basic Editor removes the module permanently.

0 0

Post a comment