Редагувати

Поділитися через


Objects (Visual Basic Add-In Model)

AddIn

The AddIn object provides information about an add-in to other add-ins.

Syntax

object.AddIn

Remarks

An AddIn object is created for every add-in that appears in the Add-In Manager.

CodeModule

Represents the code behind a component, such as a form, class, or document.

Remarks

You use the CodeModule object to modify (add, delete, or edit) the code associated with a component. Each component is associated with one CodeModule object. However, a CodeModule object can be associated with multiple code panes.

The methods associated with the CodeModule object enable you to manipulate and return information about the code text on a line-by-line basis. For example, you can use the AddFromString method to add text to the module. AddFromString places the text just above the first procedure in the module or places the text at the end of the module if there are no procedures.

Use the Parent property to return the VBComponent object associated with a code module.

CodePane

Represents a code pane.

Remarks

Use the CodePane object to manipulate the position of visible text or the text selection displayed in the code pane.

Use the Show method to make the code pane you specify visible.

Use the SetSelection method to set the selection in a code pane.

Use the GetSelection method to return the location of the selection in a code pane.

CommandBar

The CommandBar object contains other CommandBar objects, which can act as either buttons or menu commands.

Syntax

CommandBar

CommandBarEvents

Returned by the CommandBarEvents property. The CommandBarEvents object triggers an event when a control on the command bar is clicked.

Remarks

The CommandBarEvents object is returned by the CommandBarEvents property of the Events object.

The object that is returned has one event in its interface, the Click event. You can handle this event by using the WithEvents object declaration.

Events

Supplies properties that enable add-ins to connect to all events in Visual Basic for Applications.

Remarks

The Events object provides properties that return event source objects. Use the properties to return event source objects that notify you of changes in the Visual Basic for Applications environment.

The properties of the Events object return objects of the same type as the property name. For example, the CommandBarEvents property returns the CommandBarEvents object.

Property

Represents the properties of an object that are visible in the Properties window for any given component.

Remarks

Use the Value property of the Property object to return or set the value of a property of a component.

At a minimum, all components have a Name property. The Value property returns a Variant of the appropriate type. If the value returned is an object, the Value property returns the Properties collection that contains Property objects representing the individual properties of the object. You can access each of the Property objects by using the Item method on the returned Properties collection.

If the value returned by the Property object is an object, you can use the Object property to set the Property object to a new object.

Reference

Represents a reference to a type library or a project.

Remarks

Use the Reference object to verify whether a reference is still valid.

The IsBroken property returns True if the reference no longer points to a valid reference.

The BuiltIn property returns True if the reference is a default reference that can't be moved or removed.

Use the Name property to determine if the reference you want to add or remove is the correct one.

See also the Description and Type properties.

ReferencesEvents

Returned by the ReferencesEvents property.

Remarks

The ReferencesEvents object is the source of events that occur when a reference is added to or removed from a project.

The ItemAdded event is triggered after a reference is added to a project.

The ItemRemoved event is triggered after a reference is removed from a project.

VBComponent

Represents a component, such as a class module or standard module, contained in a project.

Remarks

Use the VBComponent object to access the CodeModule object associated with a component or to change a component's property settings.

Use the Type property to find out what type of component the VBComponent object refers to.

Use the Collection property to find out what collection the component is in.

VBE

The root object that contains all other objects and collections represented in Visual Basic for Applications.

Remarks

Use the following collections to access the objects contained in the VBE object:

  • Use the VBProjects collection to access the collection of projects.

  • Use the AddIns collection to access the collection of add-ins.

  • Use the Windows collection to access the collection of windows.

  • Use the CodePanes collection to access the collection of code panes.

  • Use the CommandBars collection to access the collection of command bars.

Use the Events object to access properties that enable add-ins to connect to all events in Visual Basic for Applications. The properties of the Events object return objects of the same type as the property name. For example, the CommandBarEvents property returns the CommandBarEvents object.

Use the SelectedVBComponent property to return the active component. The active component is the component that is being tracked in the Project window. If the selected item in the Project window isn't a component, SelectedVBComponent returns Nothing.

Note

All objects in this object model have a VBE property that points to the VBE object.

VBProject

Represents a project.

Remarks

Use the VBProject object to set properties for the project, and to access the VBComponents and References collections.

Window

Represents a window in the development environment.

Remarks

Use the Window object to show, hide, or position windows.

Important

Objects, properties, and methods for controlling linked windows, linked window frames, and docked windows are included on the Macintosh for compatibility with code written in Windows. However, these language elements will generate run-time errors when run on the Macintosh.

Use the Close method to close a window in the Windows collection. The Close method affects different types of windows as follows:

Window Result of using Close method
Code window Removes the window from the Windows collection.
Designer Removes the window from the Windows collection.
Window objects of type linked window frame Windows become unlinked separate windows.

Note

Using the Close method with code windows and designers actually closes the window. Setting the Visible property to False hides the window but doesn't close the window. Using the Close method with development environment windows, such as the Project window or Properties window, is the same as setting the Visible property to False.

Use the SetFocus method to move the focus to a window.

Use the Visible property to return or set the visibility of a window.

To find out what type of window you are working with, you can use the Type property. If you have more than one window of a type, for example, multiple designers, you can use the Caption property to determine the window you are working with.

You can also find the window you want to work with by using the DesignerWindow property of the VBComponent object or the Window property of the CodePane object.

See also

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.