Volume 3: Programming with the Visio Object Model disclaimer


Lab 3.1: Get the Name of an Open Visio Document



Download 0.78 Mb.
Page9/36
Date29.01.2017
Size0.78 Mb.
#11974
1   ...   5   6   7   8   9   10   11   12   ...   36

Lab 3.1: Get the Name of an Open Visio Document



Points to Consider

  1. Establish each object reference separately.

  2. Consider the document properties Description, Path or Subject for your additional information.
Exercise

  1. From your student CD, open <install path>\Labs\Vol3\Start\Get Doc.vsd

  2. From Visio, choose View > Macros > ThisDocument.Solution. This will display a form with the title GetDoc.

  3. Click the button on the form to display the name of the document.

  4. Without looking at the code for how the solution was produced, develop code to retrieve the document’s name and place it in frmExercise.

  5. When complete, run the macro.

Coding Issues


If an object is defined to be a specific type at design-time, as with the following statement

Dim oDoc as Visio.Document

it is bound to that data type at design time. This is called early binding. Many design-time checks can be made such as testing assignment statements to ensure the correct data type is being used. This creates more efficient run-time code.

If late binding is used, as with the statement

Dim oDoc as Object

the type of the object must be determined at run time, and assigning the wrong type of data to the object can cause a run-time error.

Using early binding of objects also allows you to take advantage of the Visual Basic Intellisense feature, giving you property, method, event and parameter information.

Using Visual Basic for Applications code makes distribution of your add-on easy since the Visual Basic for Applications code is part of the drawing file. Updating the code, however, is more difficult.

Demonstration: Protect Your VBA Code

  1. Open a new Visio drawing, and open the Visual Basic Editor window.

  2. From the Tools menu, choose Properties.

  3. Click the Protection tab, and click the Lock project for viewing checkbox.

  4. Enter a password and confirm it.

  5. Save and close the file.

The next time the file is opened and the VBE is accessed, the project is locked and a password must be entered to view or edit the project.


Running Your Program


To run your program:



  1. When Visio is launched

    1. Put the .exe or .vsl file into a designated Startup folder. To set the Startup folder go to File > Options > Advanced > File Locations…

    2. Register the COM-Addin and set its load behavior to Load at Startup.

  2. From the ribbon under View > Add-ons

    1. Put the .exe or .vsl file into a designated Add-ons folder. To set the Add-ons folder go to File > Options > Advanced > File Locations…

    2. Use the Add method of the application's Addons collection to programmatically add the add-ons.

      Note:

      You have to restart Visio to refresh its Add-ons list before you’ll see your program on the menu. You can also use the file paths refresh method.

  3. From the ribbon under View > Macros

    1. Create a Macro through the Visio interface.

    2. Add a public procedure into a module or ThisDocument of the VBA project for the drawing. Macros in any one open project can be accessed by another open project.

  4. When the user opens a document

Place your code or a reference to it in the DocumentOpened event in the ThisDocument module in Visual Basic for Applications.

  1. When a shortcut menu command is chosen

Create an entry in the Actions section of the ShapeSheet and make sure the add-on is either a public procedure within the Visual Basic for Applications project or is in the Add-ons path specified in the File > Options > Advanced > File Locations… dialog.

Note:

Beginning with Microsoft Visio 2003, you can publish your add-ons, templates, stencils and other files as components to be integrated with the Visio application. Publishing components is the preferred method of integrating add-ons and other content with Visio. It offers tighter integration with the Visio application, and better performance on add-on discovery. Publish Components will be covered in the section on the Visio Software Development Kit.



RUNADDON(“string”)


RUNADDON can execute a macro or call an add-on. Visio will first check for a macro of name “string” and execute that macro if one is found. If “string” is not recognized as a macro, the RUNADDON function looks for “string” in the add-on list and executes the add-on if it is found. If no add-on can be found, Visio reports no error and does nothing.


Examples:

  1. Launch an add-on called Calendar.exe

RUNADDON("Calendar.exe")

  1. Launch the (VSL-implemented) add-on whose name is Array Shapes.

RUNADDON("Array Shapes")

  1. Call the ReportStatistics macro in the ThisDocument module in the document project containing this function call. To invoke a macro in the ThisDocument module, you must preface the string with "ThisDocument" as shown.

RUNADDON("ThisDocument.ReportStatistics")

  1. Call the ReportStatistics macro in ModuleName in the document project that contains this function call.

RUNADDON("ModuleName.ReportStatistics")

For more information, see the demonstration file <install path>\Demos\Vol3\Automation and Visio\RunAddon.vsd for some examples of using the RUNADDON function.




Download 0.78 Mb.

Share with your friends:
1   ...   5   6   7   8   9   10   11   12   ...   36




The database is protected by copyright ©ininet.org 2024
send message

    Main page