IT tutorials
 
Office
 

Microsoft Visio 2010 : Distributing Templates and Stencils (part 2) - Creating a Separate Stencil for Shape and Code Delivery

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Product Key Free : Microsoft Office 2019 – Serial Number
4/18/2014 9:42:53 PM

Creating a Separate Stencil for Shape and Code Delivery

If you want to use the notes shape with any number of drawing types, you should distribute a stencil rather than a template.

Also, because the sample shape has supporting VBA code, it makes a lot of sense to distribute a stencil to contain both the shape and shape-related code.

Having VBA code in a template has the drawback that the code is copied and saved with every drawing that is created. This is not only wasteful, but makes updating the code nearly impossible. And VBA code can’t be stored in a shape. Putting code in a stencil alleviates the problem of having copies of your code saved with every drawing, but the stencil must be open for the code to run. This is hard to guarantee, so your users must be informed of this.

Creating a new stencil to hold the notes shape is easy enough, but copying the VBA code to the stencil is a bit trickier. Let’s look at both of these procedures.

Creating a New Stencil
1.
Start Visio with no documents open.

2.
On the Developer tab, click the New Stencil button. A new, unsaved stencil appears with a title such as Stencil1.

3.
Retrieve a copy of the notes shape. Open Chapter 11.vsd and copy the shape.

4.
If the drawing window obscures the stencil window, you can tile them by going to the View tab and clicking Arrange All.

5.
Switch back to the stencil by clicking its caption, or by clicking Switch Windows in the bottom right of Visio’s main window or by pressing Ctrl+Tab until you see the stencil.

6.
Right-click in the stencil window and paste. The notes shape becomes a new master, with the name Master.1.

7.
Rename the master to Notes shape.

8.
Save the stencil as Notes Shape Stencil.vss.

When you copy the code from the drawing to the stencil, you can’t put it in ThisDocument; you have to put it in a different module. Because of this requirement, you also have to update the ShapeSheet formula that calls the code.

Copying VBA Code to a Stencil
1.
Starting where you left off with Notes Shape Stencil.vss and Chapter 11.vsd open, and bring up the VBA environment.

2.
In the Project Explorer, note that there are two projects: one for the document and one for the stencil.

3.
Open the ThisDocument code module  and copy the subroutine CreateNewNote.

4.
Right-click on the Project Explorer node for the stencil and choose Insert, Module. A new item named Module1 should appear in the Modules folder, as shown in Figure 3.

Figure 3. A new item appears in the Modules folder.

5.
Double-click Module1 to bring up its code window and then paste the copied code into the window.

6.
Note the project name for the stencil. In Figure 3, it is Notes_Shape_Stencil. You need this name for modifying the ShapeSheet formula in the Notes shape master.

7.
Back in Visio, close Chapter 11.vsd.

8.
Because the code for the shape now resides in Module1 of the Notes_Shape_Stencil project, you have to make a slight change to the Action formula for the notes shape. Double-click the Notes shape master to open its editing window.

9.
In the master-editing window, show the ShapeSheet for the notes shape.

10.
Change the Actions formula as follows:

Actions.CreateNewNote =
CALLTHIS("CreateNewNote","Notes_Shape_Stencil")

Notice that ThisDocument. is removed from the first argument and that the stencil’s project name is added as a second argument.

11.
Close the master-editing window.

12.
Save the stencil.

13.
Open a new drawing, drag the notes shape into it, and test that the code works by right-clicking the shape.

Creating a Template with a Separate Stencil

Of course, you might still want to distribute a template but with the notes shape stencil and supporting code. In this case, you use a separate stencil that contains the VBA code, as you just created. Then you open a new, blank drawing (with no code in it), add backgrounds, titles, logos and other pre-drawn graphics, then open the Notes Shape Stencil via More Shapes. Save the document as a template, and you’re done!

To deploy, you send both files: the stencil and template. Users can place both files in a directory and set up the templates file location to point to this directory so that the template appears in the New screen.

Alternatively, the stencil can be placed in the My Shapes folder where it is easily opened for use with other drawings. The template expects the stencil to be in the same folder, but Visio is smart enough to searches through My Shapes as well, if the stencil isn’t found in the same directory as the template file.

 
Others
 
- Microsoft Visio 2010 : Distributing Templates and Stencils (part 1) - Creating a Template with a Document Stencil
- Microsoft Visio 2010 : Introducing Automation and VBA Code (part 3) - Calling VBA Code from a SmartShape
- Microsoft Visio 2010 : Introducing Automation and VBA Code (part 2) - Using the Macro Recorder to Generate Code
- Microsoft Visio 2010 : Introducing Automation and VBA Code (part 1) - Exploring the VBA Development
- Microsoft Access 2010 : Introduction to Relational Database Design (part 2) - Normalization and Normal Forms
- Microsoft Access 2010 : Introduction to Relational Database Design (part 1) - Rules of Relational Database Design
- Developing Custom Microsoft Visio 2010 Solutions : Creating SmartShapes with the ShapeSheet (part 6) - Adding Right-Click Actions to the SmartShape
- Developing Custom Microsoft Visio 2010 Solutions : Creating SmartShapes with the ShapeSheet (part 5) - Modifying the Text Block Using the ShapeSheet
- Developing Custom Microsoft Visio 2010 Solutions : Creating SmartShapes with the ShapeSheet (part 4) - Linking Subshape Text to Shape Data Fields
- Developing Custom Microsoft Visio 2010 Solutions : Creating SmartShapes with the ShapeSheet (part 3) - Controlling Grouped Shapes with the ShapeSheet
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us