Using Visio layers to create custom views (part 2)

After explaining the manual configuration of visio layers in part 1, it is now time to add some VBA code to the mix and build ourselves a more user friendly interface to toggle the visibility (and printability) of the layers within a drawing.

In order to use the code I will provide, you’ll need to have VBA installed with your Visio installation and enable the use of Marco’s for your drawing.

Visio Setup VBA

Visio Setup VBA

But let’s not get ahead of ourselves and start with the basics on how to setup Visio to work with VBA.

Enabling the Developer tab

In order to be able to add VBA code to a Visio drawing, you first need to add the Developer tab to the Ribbon, this can be done with the following steps:

Screens Actions

Visio Customize the Ribbon

Visio Customize the Ribbon

Right-click on a free section of the Ribbon and choose the option ‘Customize the Ribbon…’

Visio Customize the Ribbon

Visio Customize the Ribbon

Select the tab Developer under the Main Tabs and click [OK].

Visio Macro Security

Visio Macro Security

This tab also holds a Macro Security button to quickly adjust your Macro settings if required.

 

Now we have Visio all set up for the fun part!
 

 

Adding a button to your Visio drawing

The quickest way to offer your users a simple custom interface is through the use of a command button on your drawing, so let’s create one:

Screens Actions

Visio Design Mode

Visio Design Mode

Enable the Design Mode on the Developer tab of your Ribbon.

Visio Insert Command Button

Visio Insert Command Button

Add a command button to your drawing.

Visio CommandButton properties

Visio CommandButton properties

Edit your command button properties by rightmouse-click on the button and selecting CommandButton Object – Control Properties. This opens a properties window in which you can edit properties like the name and caption of the command button.

 

Building a User Form

The Command Button we have previously created needs to open a so called User Form that provided users with a simple interface to control the visibility of the layers in our drawing . So let’s create that User Form:

Screens Actions

Visio View Code

Visio View Code

Open the VBA window, by clicking on the View code button on the Developer tab of the Ribbon.

Visio Insert User Form

Visio Insert User Form

Right mouse-click on the top object in the left pane (Drawing1 in the picture) and select Insert – UserForm.

Visio add User Form Controls 2

Visio add User Form Controls 2

You can now add multiple controls to the User Form, to create the custom interface for the users. Use the Properties Window to name each control with a easily identifiable name.

Visio layers view selection User Form

Visio layers view selection User Form

I’ve created a user form with labels representing the Layer names as defined in the Visio drawing and check boxes for the visibility and print properties of each layer. The command button is in place to close the user form, so they can use the drawing normally.

 

Stick around for the final part to get all the VBA code I used and a downloadable sample drawing.
The best goodies are yet to come!

 

 

This post is part of a serie of 3 posts to fully cover the Use of Visio layers to create custom views:
Using Visio layers to create custom views (part 1)
Using Visio layers to create custom views (part 2)
Using Visio layers to create custom views (part 3)

Esther Barthel
Solutions Architect at cognition IT

Esther has been working in different roles and functions as an IT consultant ever since she finished her Masters degree in Computer Science in 1997. She has worked as a web developer, database administrator, and server administrator until she discovered how Server-Based Computing ( SBC ) combined servers, desktops, and user experience in one solution. Esther has been specializing in virtualization solutions such as SBC, VDI, application, and server virtualization for over eight years now and is currently working as a Senior Consultant at PepperByte, where she designs and implements Citrix® solutions for both small-business and large-enterprise infrastructures scaling from 100 to 15,000 users.
In january 2014 her first book Citrix XenApp 6.5 Expert Cookbook was published by Packt Publishing.

Esther is awarded as a Citrix Technology Professional (CTP) from 2015 - 2017.
Esther is awarded as a Microsoft Most Valuable Professional (MVP) in 2017.

Esther is a Citrix Certified Expert – Virtualization (CCE-V), Citrix Certified Professional – Mobility (CCP-M), Citrix Certified Professional – Networking (CCP-N) and RES Software Certified Professional (RCP).

Tagged on: ,

5 thoughts on “Using Visio layers to create custom views (part 2)

  1. Pingback: virtuEs.IT

  2. Pingback: virtuEs.IT

  3. Pingback: Using Visio layers to create custom views (part 1) « virtuEs.IT

  4. Pingback: Using Visio layers to create custom views (part 3) « virtuEs.IT

  5. Pingback: Microsoft Visio