The information in this article applies to:
SUMMARY
The programming object model in Microsoft Office 97 for Windows allows you
to create a custom dialog box (a UserForm) by using a Microsoft Visual
Basic for Applications macro.
MORE INFORMATION
The Visual Basic objects in Microsoft Office 97 provide the objects and
methods you need to access Visual Basic projects and their elements. The
top-level objects that controls the Visual Basic objects is the VBE object.
The VBE object is the root object that contains all other objects and
collections represented in Visual Basic for Applications. You can control
the VBE object through the Application object. The VBE object contains the
VBProject collection, which represents all the projects that are open in
the development environment.
The Microsoft Visual Basic for Applications Extensibility Object LibraryFor the following Visual Basic code in this article to function, first load the "Microsoft Visual Basic for Applications Extensibility" object library in the project. This example uses Microsoft Excel, but the steps are similar for any of the Microsoft Office program. To add a reference to the "Microsoft Visual Basic for Applications Extensibility" library to your project, follow these steps:
For additional information, please see the following article in the Microsoft Knowledge Base: Q173707 OFF97: How to Run Sample Code from Knowledge Base Articles Macro to Count the Number of Visual Basic ComponentsMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:http://www.microsoft.com/support/supportnet/overview/overview.aspTo return the number of all modules, class modules, and UserForms in the active project in a message box, type the following code in the new module:
Or use the following code:
Creating a New UserFormTo create a new UserForm, use the Add method of the VBComponents collection and specify vbext_ct_MSDForm. For example, type the following code in the new module:
Changing the Name and Other Properties of a UserFormTo change the name of a UserForm, change the value of its Name property. To change the names of other properties (for example, title, height, or width), change them through the Properties collection of the VBComponent object. The following example creates a new UserForm and then changes the name, caption (text that appears in the title bar), height, and width of the newly created dialog box:
Adding Controls to the UserFormTo add a new control to a UserForm, first use the Designer object of the corresponding VBComponent object. The Designer object allows you to manipulate the design of a UserForm. The Designer object contains a Controls collection. To add a new control, add it to the Controls collection. The following example adds a check box control to a newly created UserForm and sets the name, caption, position, and size of the control:
For additional information, please see the following article in the
Microsoft Knowledge Base:
Q157319 XL97: Problems When you use Macro to Add Control to UserForm REFERENCESFor more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base: Q163435 VBA: Programming Resources for Visual Basic for Applications Additional query words: vba
Keywords : kbdta kbdtacode xlvbahowto |
Last Reviewed: November 13, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |