Saturday 14 April 2018

Working with Project Window

Working with Project Window

When you are working in VBE, each file open is called a Project. You can think of a project as a collection of objects. You can expand a project by clicking plus sign (+) at the left of the project’s name in Project window. Contract a project by clicking minus sign (-) to the left of the project’s name in Project window. Or you can simply double click the items to expand or contract them.

Every project expands to show at least one node. In our previous image we have “SOLIDWORKS Objects”. This node expands to show an item for Solidworks application. If the project has any VBA module, the project listing also shows a Module node. A project can also contain a node called Forms, which contains UserForm objects (which holds custom dialog boxes).

The concept of Object may not be clear to you at this moment. However, things become much clearer in subsequent topics. Don’t be too concerned if you don’t understand what’s going on at this point.


Adding a new VBA module

Follow below steps to add a new VBA module to a project:

  1. Select the projects name in the Project Window.
  2. Select Insert ⇨ Module.

Or

  1. Right click the project’s name.
  2. Select Insert ⇨ Module from the shortcut menu.

When you record a macro or create a blank macro, your CAD application automatically adds a module to hold the codes.


Removing a new VBA module

If you want to remove a module from Project window then follow below steps for that:

  1. Select the module's name in the Project Window.
  2. Select Fie ⇨ Remove.

Or

  1. Right-click the module’s name.
  2. Select remove from the shortcut menu.

VBE always trying to keep you from doing something that you will regret, hence it will ask if you want to export the code in the module before deleting the code. And in most cases, you don’t want to export. If you do want to export the code, please see next section.


Exporting and Importing of objects

Every object in a VBA project can be saved to a separate file. Saving an individual object in a project is known as Exporting. Reason for exporting a file is that you can also import objects in 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.

Below steps show how to export an object:

  1. Select an object in the Project window.
  2. Select File ⇨ Export file or press Ctrl + E.

You get a dialog box that asks for a filename. Note that the object remains in the original project only a copy of the object is exported.

Importing an object is also a similar process, which is shown below:

  1. Select the project’s name in the Explorer window.
  2. Select File ⇨ Import file or press Ctrl + M.

You get a dialog box that asks for a file. Locate the file and click open. You should only import a file if was export by using File ⇨ Export file command.

No comments:

Post a Comment