From the VBE Tools menu you can get to some very useful menu options.
Choose the Options menu under Tools. This displays a tabbed dialog box. Choose the Editor tab. One of the check boxes on this tab is “Require Variable Declaration.” Checking this option causes the keywords Option Explicit to be inserted at the beginning of any new module or form added to the project. It does not, however, add Option Explicit to already existing forms and modules. Option Explicit forces any variable name used in code to be explicitly defined. This is very helpful at design time in catching any mistyped variable names.
Objects other than Visio objects can be accessed by Visual Basic for Applications, but the Visual Basic for Applications environment must first be notified. This is done from the References menu under Tools. The dialog box displays all object libraries installed on the local machine. Just check the ones that you want to access. For example, if you want to control Excel from the Visio application, from the References menu, check the appropriate Excel object library.
The functionality of Digital Signatures was added to Visio 2002. Digital Signatures allow you to add an extra level of security to your VBA projects. Using digital certificates, a developer can digitally sign a project and be identified as a trusted source. When a Visio document with a VBA project is loaded, Visio checks to see whether the project has been digitally signed by a trusted source before loading it. If it has, the project will be loaded under any security level. If it has not, Visio will load the project based on the current security level set for the Visio application. Macro security settings in Visio can be found in the Trust Center.
For more information on Microsoft Office security, search the Microsoft Developer Web site (msdn.microsoft.com) for “Digital Signing”.
Once an object library is part of the project, its objects can be viewed with the Object Browser. Choose View > Object Browser (or F2) to use the browser.
From the Object Browser you can view the hierarchical structure of any object library.
You can search for objects by name.
Once an object is selected, you can view its properties, methods, and events.
Values of constants defined in a type library can also be determined from the object browser.
To turn off the Object Browser, just close the window.
Questions -
Define Automation.
-
What actually happens when one program uses Automation to drive another program?
-
What allows Visio to be a controller and a server at the same time?
-
What function does a digital signature provide?
Answers -
Automation allows one program to incorporate the functionality of another by using objects exposed by the other program.
-
The server application returns a handle to an object. The controller application can use this handle to ask the server application to do things with this object.
-
Because Visio has embedded VBA it can be used as a controller. Because it exposes its object model it can be used as a server.
-
Using digital certificates, a developer can digitally sign a project and be identified as a trusted source.
Automation and Visio Technology
In this section, we will tie together some of the concepts that were learned in the ShapeSheet modules with Automation objects from the Visio object model.
We have spent a good deal of time learning about the ShapeSheet. The ShapeSheet is important to understand in order to effectively automate Visio because each cell in the ShapeSheet is effectively a property that you can control through automation. However, most ShapeSheet cells will not be found directly in the Visio Object Model. Instead, you will access them indirectly through the Cells or CellsU property of the Shape object.
Overview
Now you will learn about how you can use SmartShapes as part of a larger solution by using Automation to control the Visio application and the objects within it.
In this module you will look in depth at the Visio Object Model. You will analyze each object and begin the process of discovering its methods and properties.
You will learn different strategies for when and how to run your programs and issues to consider when choosing a platform for your program. Finally, we will look at other resources that are available to help in you in learning about and using the Visio Object Model.
This slide shows a portion of the Microsoft Visio object model. A richer, but not complete view of the Visio object model is on the following page. The image shows the object model of Visio 2003, but at this high level view it is still shows the major components and the basic structure of the model.
It is not as complicated as it looks; many of the objects are used primarily to access other objects, and you’re unlikely to use all of the objects in a given program. For example, you’ll probably do more with shapes than you will with documents and pages; you may never manipulate layers from a program, although Visio exposes layer objects so you can if you need to.
Many objects in the model correspond to items you can see and select in Visio windows. For example, a Page object corresponds to a drawing page; a Shape object can represent anything on the drawing page that you can select with the pointer tool—a shape, a group, a guide or guide point, or an object that is linked or embedded in a Visio drawing.
The Application object represents a running instance of the Visio application, and this is where you’ll typically start. In some circumstances you can start at the document or the page. The Application object has properties that return references to “next objects” in the model—for example; the Documents property returns a reference to the Documents collection, which represents all of the documents that are open in the instance. You would retrieve a particular document by using the Item property of the Documents collection. Use the Pages property of that Document object to get its Pages collection, and so on, down to a particular shape or even a particular formula of that shape, represented by a Cell object.
The Microsoft Visio global object is automatically available to Microsoft Visual Basic for Applications (VBA) code that is part of the VBA project of a Visio document. The Visio global object is not available to code in other contexts. The global object holds references to such properties as ActiveWindow, ActiveDocument, and ActivePage. These properties are also available through the Application object if you are building your solution outside of VBA within Visio.
Share with your friends: |