By now you can fully appreciate Visio’s breadth and depth. With stencils and templates you can quickly create innumerable types of diagrams. Intelligent-behaving SmartShapes let you draw more efficiently. Data-linking makes your creations more valuable. And add-on tools save you time and offer advanced functionality.
You’ve probably started to formulate ideas for your own custom diagram types. Maybe your company needs a special flavor of an existing template, or you are salivating at the idea of creating your own SmartShapes that will save you time.
You can get pretty far by creating your own libraries of existing shapes, or importing clip art and then building a template. But it gets really interesting when you start adding intelligent behavior to your SmartShapes using the ShapeSheet or automating drawing tasks using macros.
So, if you are just technical enough to be dangerous (did you ever get an “A” in math or take a screwdriver to something that wasn’t broken?), this chapter is for you! But be warned: once you get a taste for developing Visio, you might not want to stop!
This chapter explores the basics of creating smarter shapes using Visio’s ShapeSheet, programming sophisticated behaviors using Visual Basic for Applications (VBA) macros, and deploying your solution via stencils and templates. The discussion concentrates on working through a targeted example that will demonstrate some of the capabilities of advanced Visio customization. I hope this gives you an idea of what you can do with Visio and spurs your imagination to experiment further.
The ultimate goal of this chapter is to create a smart notes shape, four of which are shown in Figure 11.1.
Figure 11.1. Four notes shapes. Shape Data holds the note number, and the parts of the shape maintain form no matter what length it is.
The notes shape has a few...notable...features. Throughout this chapter, you will learn how to implement all of them.
• It has two text blocks: the note and the note number.
• The number is set in a Shape Data field, the note text by selecting and typing.
• When it is stretched, the box around the number stays square, and the point of the arrow maintains consistent pointiness.
• The note text is justified to the end of the arrow, nearer the subject of the notes shape, no matter the length of the shape.
• Right-clicking on Properties opens a convenient Shape Data window for changing the value of Number.
• Right-clicking on Create New Note calls a Visual Basic macro that creates a new notes shape just under the one that you clicked and increments the value of Number.
Before you start, you need to make sure that the Developer tab is visible. Doing so adds some functions that make advanced customization possible. Recall that we mentioned it in Chapter 7, “Working with Data,” where activating it gave us extra fields in the Define Shape Data dialog.
Turn it on by right-clicking a blank area of the Ribbon and choosing Customize the Ribbon. On the right side of the dialog, check Developer in the Main Tabs list.
You see the Developer tab at the far right end of the Ribbon. Examine it, and notice groups of controls, such as Code, Add-ins, Controls, Shape Design, Stencil, and Show/Hide. If you’ve installed the Visio 2010 Software Development Kit, you also see the SDK Tools group, which offers a few more handy tools.
The ShapeSheet is the spreadsheet-like interface that resides behind every Visio shape. It supports functions similar to Excel, so you can actually program behaviors into shapes without typing lines of code.
Perhaps you have discovered the mysterious Show ShapeSheet button on the Developer tab, with its big blue, red, and gray table icon that beckons clicking whenever a shape is selected. Click it and the ShapeSheet window appears. This is the key to adding sophistication to your shapes. Figure 11.2 shows the ShapeSheet for a simple rectangle drawn with the Rectangle tool.
Figure 11.2. The ShapeSheet for a simple rectangle. The Protection and Miscellaneous sections are collapsed, and formulas, not values, are showing.
The ShapeSheet is a special-purpose, brightly colored spreadsheet, similar to Microsoft Excel (circa 1992, but I digress...). The ShapeSheet reveals the behind-the-scenes definition of every Visio shape, holding information about its size, position, geometry, formatting, protection, text block, Shape Data fields, and more.
Remember that if you are just drawing with Visio and creating pure graphical symbols, you do not need the ShapeSheet. However, if you want a shape to be smarter than ordinary clip art, you need to understand how it works.
Here’s a list of just some of the things you can do via the ShapeSheet:
• Create smart geometry that behaves well when shapes stretch. In Figure 11.3, you see “smart” and “dumb” versions of three shapes. Notice that the smart versions don’t uniformly stretch. Instead, parts of these shapes maintain proportion, which increases visual consistency and leaves more space for text.
Figure 11.3. SmartShapes that resize intelligently maintain graphic consistency and utilize space better for text. All parts of “Dumb” shapes mindlessly stretch, which looks inconsistent, ugly and wastes space that could be used by text.
• Add custom Actions to the right-click menu and make geometry, formatting, text, and even code respond to them. Figure 11.1 shows two custom actions atop the menu.
• Create multishapes that can change form via right-mouse clicks or Shape Data field values. Imagine a stop-light symbol that can be set to glow red, yellow, or green at the click of a mouse or an electrical switch symbol that closes or opens when on or off right-mouse actions are selected. You saw examples of these in Chapter 6, “Working with Individual Shapes.”
• Store data and calculations in shapes, hidden from users using User-defined cells instead of Shape Data fields.
• Conditionally change the color or other formatting of a shape based on its size, position, or the value of a Shape Data field.
• Display data and calculation results in a shape’s text.
• Protect a shape’s size, position, formatting, text, and other attributes from being edited.
Reading about ShapeSheet theory can be duller than a whetstone in a spoon factory. You will retain more information if you fiddle with it in real-life. So let’s jump in and take it for a spin!
Your first task is to build the right side of the notes shape—just the arrow portion. Keeping the point a consistent size is the perfect exercise for understanding the ShapeSheet’s capabilities. Before long, the ShapeSheet will be familiar, and you will have built a functioning, useful SmartShape.
Access this video file through your registered Web Edition at my.safaribooksonline.com/9780132182683/media.
Access this video file through your registered Web Edition at my.safaribooksonline.com/9780132182683/media.
LET ME TRY IT
Figure 11.4. Changing the x-location of Geometry1.X2 to be half of the width of the shape. Notice that the point represented by the selected ShapeSheet cell is highlighted with a black square in the drawing window.
This is also a great way to find out the name of any cell in the ShapeSheet. Select any cell, type “=”, then click another cell. You will see the name of the target cell in the source cell. Press Esc to cancel the editing and leave the source cell unchanged.
Figure 11.5. A rectangle becomes a pointy box thanks to ShapeSheet manipulation. The shapes at the top show how your example currently behaves when resized to different widths.
Figure 11.6. The length of the head of the pointed box is always one-half the height of the body. No matter how long or thick the shape is, the sharpness stays constant. When many differently sized shapes are on the page, there is an uncluttered, visual consistency.
The coordinates for shapes and pages are the same as you learned in algebra and geometry, namely Cartesian coordinates. The origin is at the lower-left of a shape or page; positive directions are to the right and up.
The Pin of a shape is the same as the rotation point that you see when you mouse over the “lollipop” handle above a shape. In the ShapeSheet, you have seen four cells that define that pin: PinX, PinY, LocPinX and LocPinY cells.
Imagine pinning a note to the wall. The location of the hole made in the wall is defined by PinX and PinY, relative to the lower-left corner of the wall. The location of the hole in the note is defined by the LocPinX and LocPinY. These are relative to the lower-left corner of the note. In this analogy, the wall is the page, and the note is the shape.
Shape developers talk about “local” coordinates and “parent” coordinates. For a shape, LocPinX, LocPinY and Geometry coordinates are local to the shape. PinX, PinY and Angle are relative to the parent: the page, or a containing group.
Budding shape developers are often tripped up by the difference between local and parent coordinates, especially when working with subshapes inside a group.
You’ve just seen how to smarten the geometry points of a single shape. Next, you try smartening the subshapes within a group.
There are numerous reasons to create grouped shapes. If you need multiple text blocks in a shape, or if you need different line or fill colors and styles, you need to group shapes together. Grouping shapes can also simplify programming by isolating different behaviors in separate subshapes, as you see shortly.
Be warned that once you start adding ShapeSheet smarts to a group and its member shapes, ungrouping becomes very destructive. If you need to alter parts of your group, be sure to subselect the appropriate shapes, or open the group window by right-clicking and choosing Group, Open Group. Ungrouping can blow away a lot of your ShapeSheet work, so don’t do it!
In the next example, you incorporate your pointy box into a well-behaved notes shape. The arrow is grouped together with a number for easy identification. The entire shape exhibits behavior similar to the arrowhead in that the number box doesn’t change when you stretch the whole shape. Figure 11.7 contrasts the way the smartened shape resizes with an unsmart box grouped with the arrow.
Figure 11.7. The smartened notes shape resizes properly in contrast to the behavior you get when a rectangle and arrow are simply grouped together.
Access this video file through your registered Web Edition at my.safaribooksonline.com/9780132182683/media.
LET ME TRY IT
Figure 11.8. The desired dimensions of the subshapes for your smart notes shape. Note that the widths of the Box and Arrow shapes depend on the height of the group.
To add user cells, right-click anywhere in the ShapeSheet window and choose Insert Section.
User.BoxWidth = Height
User.BoxHeight = Height
User.ArrowWidth = Width - Height
User.ArrowHeight = Height
Note, you get “User.” for free, don’t type this when changing row names! You have now defined the important size parameters for the subshapes.
Width = GUARD(Sheet.3!User.BoxWidth)
Height = GUARD(Sheet.3!User.BoxHeight)
LocPinX = GUARD(0)
LocPinY = GUARD(0)
PinX = GUARD(0)
PinY = GUARD(0)
The width and height of the box refer to the user-defined parameters stored in the group’s ShapeSheet. Note the cross-sheet referencing syntax for these two formulas: Sheet.ID + exclamation point + cell-name.
User-defined rows have two cells: Value and Prompt. The full names of the cells are, for example: User.BoxWidth.Value and User.BoxWidth.Prompt. Since the Value cell is the default, Visio lets you use more compact notation and leaves “.Value” off, as we did in our formulas above.
The pin is located at the center of a shape by default. You can reduce calculation by moving it to the lower-left corner, which is point 0,0. The formulas you just entered cause the LocPin to be in the lower-left corner of the box, and its Pin to be in the lower-left corner of the group. Zeros across the board! Note that this changes the rotation point of the shape to the lower-left corner as well. But we won’t be rotating the box, so this is just fine.
The GUARD function prevents users from accidentally moving the shapes and breaking the smart formulas. It also tells Visio to preserve the formulas when the shape is copied.
Width = GUARD(Sheet.3!User.ArrowWidth)
Height = GUARD(Sheet.3!User.ArrowHeight)
LocPinX = GUARD(Width)
LocPinY = GUARD(0)
PinX = GUARD(Sheet.3!Width)
PinY = GUARD(0)
Similar to what you did with the Box, these formulas simplify the positioning calculations by moving the LocPin to an edge—this time to the lower-right corner of the arrow and of the group.
If you resize your group, the Box should stay square, the point of the Arrow should maintain its shape, and there should be no gaps between the two subshapes.
By linking the size and position of the subshapes to user-defined parameters, our notes shape behaves graphically correct when resized. Now we need to attend to the text. The text in the Box should be linked to a number field in the group. In the next exercise, you create a Shape Data field in the Group shape, then refer to it from the Box to create data-linked text.
LET ME TRY IT
Figure 11.10. Linking subshape text to the parent group’s Shape Data by inserting a custom field.
If you select the notes shape and then start typing, you see that the text is centered and that the text block is as wide as the whole shape. This text belongs to the group itself, not to the box nor the arrow. You really want the text block to match the width of the arrow, and it should be right-aligned so that the text is aligned with the point of the arrow.
You could use the Text Block tool to make the text block less wide, but it would still size proportionally when we stretched the shape and wouldn’t line up properly. The text block needs to be exactly as wide as the arrow subshape. To do this requires the ShapeSheet.
LET ME TRY IT
TxtWidth = GUARD(User.ArrowWidth-Height*0.5)
TxtPinX = GUARD(Width-Height*0.5)
TxtLocPinX = TxtWidth
The Text Transform cells govern the size and position of the text block inside a shape. Note how the TextPin and TextLocPin cells are analogous to Pin and LocPin cells of the shape. It is as if the Text is a subshape inside a group.
TxtWidth is the width of the actual text block. The formula above makes it as wide as the body of the Arrow minus the width of the arrow tip. This keeps the text from getting scrunched inside the point. The text’s local pin x is on the right at TxtWidth. The text’s pin is positioned where the head of the arrow begins, at Width - Height*0.5.
The notes shape is still missing the two right-click actions shown in Figure 11.1: one to open a Shape Data dialog and one to call some custom code. You can set up both of them now and then transition into the section about VBA programming to make the second item actually work.
Actions.Properties.Action = DOCMD(1312)
Actions.Properties.Menu = "Properties..."
Actions.CreateNewNote.Action =
CALLTHIS("ThisDocument.CreateNewNote")
Actions. CreateNewNote.Menu = "Create New Note"
The Menu cells expect strings. If you have trouble, make sure there are double quotation marks on both sides of the text. Whatever you type in the Menu cell will show in the right-click menu.
The Action cell does the actual work. Actions can be performed in a number of ways such as setting ShapeSheet formulas, calling Visio functions, or invoking macros or add-on code. The first action uses the DOCMD ShapeSheet formula to call command 1312. This is the command id for showing the Shape Data pop-up window. The second Action uses the CALLTHIS function to access a VBA macro that you will write later on.
Figure 11.11 shows how the Actions section for the notes shape should look.
Figure 11.11. Actions defined in the ShapeSheet appear when right-clicking the shape.
That wraps up the ShapeSheet portion of this project, and you’ve achieved quite a lot! You’ve created a smart-sizing arrow. You grouped the arrow with the number box and created resizing smarts that keep the box square, and the arrow using the remaining space. You linked the box’s text to a Shape Data field in the group, and you configured the notes text so that it is nicely aligned within the arrow. To top it all off, you added custom right-click actions that show Shape Data and call VBA macros. Phew! Now it’s time to write that macro, and then discuss ways to deploy your SmartShape in a stencil with a template.
You’ve seen that the ShapeSheet is a nifty tool you can use to turn your Visio shapes into intelligent graphical mechanisms. For some tasks, using a programming language is more appropriate. Luckily, Visio has a built in development environment, just like other applications in the Microsoft Office suite.
Visual Basic for Applications, or VBA, is a programming language similar to BASIC, which has been around for eons and is renowned for its friendly, English-based syntax.
Because the VBA environment is built in to Visio, you can start using it in a matter of seconds. It is a wonderful tool for experimenting with Visio’s object model, properties and methods, and offers a quick way to get your developer feet wet, so to speak.
? Visio.ActivePage.Shapes.Count
Then press Enter. The number of shapes on the active Visio page is printed on the next line, as shown in Figure 11.12.
Figure 11.12. Using the Immediate window to query Visio. In this window, “?” is shorthand for “Print” and instructs VBA to output the result of the following statement.
? Visio.ActivePage.Name
? Visio.ActiveDocument.Pages.Count
? Visio.ActivePage.Shapes.Item(1).Text
You can change the number in the parentheses to get the nth shape on the page.
ActiveWindow.Selection(1).AutoConnect ActiveWindow.Selection(2),
visAutoConnectDirDown
Note that there is no ? at the beginning of this statement. You aren’t asking for an output; you are telling Visio to do something. In this case, to connect the first selected item to the second, in the down direction. Note that you used shorthand by not typing out Item. Instead of Selection.Item(1), you can type Selection(1). Figure 11.13 shows the result.
Figure 11.13. Connecting two selected shapes using a code snippet in the Immediate window.
Double-click on ThisDocument in the Project Explorer. A blank white area occupying the bulk of the VBA window appears, along with a blinking text cursor. This is the code module called ThisDocument.
Public Sub HelloVisio()
Dim s As String
s = "Page: " & Visio.ActivePage.Name
s = s & " has " & Visio.ActivePage.Shapes.Count
s = s & " shapes."
MsgBox s
End Sub
A few notes about this: s is a variable, which you declared to be a string in the first line, using the Dim statement. You then built s into a message by concatenating bits of text. For strings, you use the & operator to add chunks of text together. So ”Visio” & “Guy” = “Visio Guy”. Finally, you invoke a pop-up message box to display the text stored in s. The code in HelloVisio will pop up a message displaying the name of the active page, and the number of shapes it contains.
Note that Visio doesn’t have a central repository for macros like Word does—there is no “Normal.dot” for holding code that can be accessed from all documents. However, stencils can also have VBA code, which can serve a similar purpose.
You can also run macros from Visio by clicking the Macros button on the View and Developer tabs.
Public Sub ListShapes()
Dim i As Integer
Dim shp As Visio.Shape
For Each shp In Visio.ActivePage.Shapes
i = i+1
Debug.Print i & ". " & shp.Text
Next
End Sub
Debug.Print instructs VBA to output information to the Immediate window.
Figure 11.14. Sub ListShapes outputs the text of every shape on the page to the Immediate window. Because item 7 lists no text, it must be the connector, since it is the only shape in the drawing that has no text!
The Immediate window allows you to quickly try bits of code, and the IntelliSense drop-down lists make it even easier to discover functions for Visio objects.
Visio also has a macro recorder that generates VBA code while you manipulate objects onscreen. You can then modify and reuse this code. Using the recorder is a great way to learn how to program Visio, too.
Figure 11.15. Overly verbose macro recorder code for duplicating a shape.
Here are a few things to note about the code in Figure 11.15 and macro recording in general:
• Two lines start with an apostrophe and appear green in the VBA editor. These are comments that have no effect on how the code runs, but remind humans of the intent of the code. Comments are a good thing. Use them to document the purpose of your code blocks.
• When you record macros in Visio 2010, six lines are added regarding DiagramServices that aren’t really related to the actions you performed. In Figure 11.15, these are the first four lines and the last two lines. Don’t worry about understanding them right now.
• The macro recorded the selection of a particular shape. In Figure 11.15, find the line that ends with ...ItemFromID(4), visSelect. (It’s the longest line.) If you try to reuse this macro for a page that doesn’t have a shape with ID=4, the code fails. Note: this ID is the same ID that we have talked about earlier when referring to shapes in ShapeSheet cells.
• To make a macro that duplicates selected shapes and moves them a specific amount, just delete this line plus the two lines that end with ...DeselectAll.
• Visio wraps the macro in an “undo scope.” This creates a named set of commands that can be undone in one action. Even if the code performs many operations, one undo restores your drawing to its original state. The name of the undo scope is shown in the Undo/Redo buttons at the top left of the Visio window.
• Macro code isn’t perfect. You’ve just seen that Visio inserted a bunch of extra stuff like Diagram Services and undo scopes that muddy the code. Plus, selecting a shape by ID is not something you can easily re-use without modification. So use the macro recorder to learn which commands are needed for particular operations. However, be prepared to clean up the code that is generated, and modify it for general use.
Now that you’re familiar with the VBA environment and basic subroutines, it’s time to connect the notes shape with some useful code.
LET ME TRY IT
Actions.CreateNewNote.Action=CALLTHIS("ThisDocument.CreateNewNote")
The CALLTHIS ShapeSheet function looks for the sub CreateNewNote in the ThisDocument VBA module. We know where ThisDocument is, we just need to add CreateNewNote to it.
Public Sub CreateNewNote(ByRef shp As Visio.Shape)
End Sub
Public Sub CreateNewNote(ByRef shp As Visio.Shape)
MsgBox "Hi, my name is CreateNewNote!"
End Sub
Now you can test the code from the shape. Don’t run this sub from VBA, as you did previously. Instead, return to Visio, right-click the notes shape, and choose the second item. The message box appears, showing the test message you just coded.
Public Sub CreateNewNote(ByRef shp As Visio.Shape)
' Get the location and height of the existing shape:
Dim shpNew As Visio.Shape
Dim px As Double, py As Double, h As Double
px = shp.Cells("PinX").ResultIU
py = shp.Cells("PinY").ResultIU
h = shp.Cells("Height").ResultIU
' Drop a copy of the shape onto the page:
Set shpNew = shp.ContainingPage.Drop(shp, px, py - h)
' Increment the number field:
Dim n As Integer
n =
shp.Cells("Prop.Number").ResultInt(Visio.VisUnitCodes.visNoCast, 0)
' Set the new shape's number to be one more than the old:
shpNew.Cells("Prop.Number").ResultIU = n+1
' Set the new shape's text:
shpNew.Text = "Notes shape, number = " & n+1
End Sub
An interesting feature of the CreateNewNote subroutine is the code used to get and set values from the ShapeSheet. The Cells method takes a string argument that matches the name of a cell in the ShapeSheet. In this way, shp.Cells gives you access to the entire ShapeSheet.
Many budding Visio developers scour the SDK documentation looking for the properties Width, Height, Geometry1X1, to no avail. Cells is the key they miss. When you have a cell object, you can ask for its value in “internal units” by using ResultIU. Internal units in Visio are inches. If you use a different measurement system, you can use Result instead. For example, shp.Cells(“Width”).Result(“cm”). You can also get a cell’s formula—for example, shp.Cells(“Geometry1.X1”).Formula.
Access this video file through your registered Web Edition at my.safaribooksonline.com/9780132182683/media.
Now that you have a super-smart notes shape that has custom ShapeSheet behavior and is linked to a macro, it’s time to share it with your team...or the world! There are several ways to go about this; let’s explore them.
Most Visio templates open several stencils that are separate files. This is great if a template needs access to lots of shapes and stencils. However, for solutions that need only a few master shapes, it makes sense to put these masters in the local document stencil.
Recall from Chapter 2, “Working Around the Diagram,” that the document stencil is part of the Visio document, so if you choose this route, you only have to distribute one file: the template itself.
LET ME TRY IT
To distribute this template to your team, you have only one template file to send around instead of a template plus a stencil.
When users double-click on Notes Shape Template 1.vst in Windows Explorer, Visio opens an unsaved copy of the drawing, and the Notes shape master is visible in the document stencil.
Because the template contains VBA code, you see a warning alerting you to the presence of macros and asking you to enable or disable them. You can change the level of macro security by visiting File, Options, Trust Center, Trust Center Settings, Macro Settings. Users that have the highest setting will not see any warning about your macros, and the CreateNewNote code won’t run at all.
Rather than loosen your macro security settings, you can also specify certain directories on your system that contain trusted code. To add a trusted location, visit File, Options, Trust Center, Trust Center Settings, Trusted Locations, and then add the path. Files with VBA macros stored in a trusted location do not present a macro security alert, and will run just fine. Perhaps members of your team could create a trusted folder called “My Team” and place macro-enabled templates and stencils from fellow employees in this folder.
Usually, you start new drawings by visiting the template gallery at File, New, Choose a Template. It’s nice to have your custom templates can show up in this screen as well. You can inform Visio of special folders that contain your content, so that your custom templates appear in the Backstage area.
Go to File, Options, Advanced. Scroll down to the bottom of the options and click the File Locations button. In the dialog that appears, enter the path where you would like to store your custom templates, as shown in Figure 11.16.
Figure 11.16. Specifying custom template paths.
You can have multiple locations for custom templates. Just separate multiple paths with semicolons. After you click OK, you need to restart Visio for the changes to take effect, but thereafter your custom template will appear in the new gallery, as Figure 11.17 shows.
Figure 11.17. A custom template appears in the template gallery. Note the absence of a preview. Show Me 11.5 discusses how to add previews.
Access this video file through your registered Web Edition at my.safaribooksonline.com/9780132182683/media.
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.
LET ME TRY IT
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.
LET ME TRY IT
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.
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.
If you enjoyed the exercises in this chapter, are fired up about Visio solution development and are thirsting for more, I’ll show you where to drink.
Your first stop is to get the Visio 2010 Solution Development Kit (SDK). You can download it from Microsoft. The easiest way to find it is to search for “Visio 2010 SDK.”
The SDK contains plenty to read, code samples in VBA, VB.NET, C# and C++ that you can copy, modify and learn from, as well as ready-to-go tools to help you with repetitive or difficult tasks. When you install the SDK, the tools even show up on the Developer Ribbon tab, in the SDK Tools group.
Of course, nothing beats curling up on the couch on a cold rainy day, with a cup of coffee and a real, live book about computer programming. (Yes, I’m from Seattle.) Although there are plenty of books about Visio, only a handful deal with developer-specific issues. Here are the top entries:
• Visio 2003 Developer’s Survival Pack by Graham Wideman
• Visualizing Information with Microsoft Office Visio 2007 by David J. Parker
• Microsoft Visio 2010 Business Process Diagramming and Validation by David J. Parker
• Developing Microsoft Visio Solutions by Microsoft Press and Microsoft Corporation
The Visio 2003 Developer’s Survival Pack is getting long in the tooth, but it is still relevant. If you’re eager to learn the fine details of shape creation and Visio automation, it is worth a look. Because Visio 2010 introduced major new customization possibilities, you should keep an eye on the “What’s New” section of the developer help that comes with the SDK. But the Pack still has tons of good information to offer.
David Parker’s Visualizing Information with Microsoft Office Visio 2007 combines both power-user tips and developer information in a single book. It covers in-depth the data graphics features that were introduced in Visio 2007 and are still a big part of Visio 2010. This book helps fill in a lot of the gaps left open by the Survival Pack’s age.
Developing Microsoft Visio Solutions is available online (http://msdn.microsoft.com/en-us/library/aa245244%28v=office.10%29.aspx) from MSDN. Although it was written for Visio 2002, it still contains plenty of relevant information.
Plenty of websites and newsgroups contain information about the ShapeSheet and programming Visio. Using a search engine is a good way to find resources, especially if you use Visio-specific terms, such as ShapeSheet, “SmartShape” or “PinX.” Here’s a short list of some good places to start.
• Visio Guy (http://www.visguy.com)
• Visio Guy Forum (http://www.visguy.com/vgforum)
• John Marshall’s Visio Information (http://visio.mvps.org/)
• David Parker’s Visio blog (http://davidjpp.wordpress.com/)
• John Goldsmith’s visLog (http://visualsignals.typepad.co.uk/vislog/)
• Visio Insights (http://blogs.msdn.com/b/visio/)
With the exception of Visio Insights, all these websites are run by Visio MVPs (Microsoft Most Valuable Professionals) who are knowledgeable Visio experts but not employed by Microsoft. Visio Insights is the official blog of the Microsoft Visio product team and has lots of good “insider” information.
I hope you found this whirlwind tour of Visio customization useful and inspiring. Although this chapter covers a lot of information, even more has been left out! Nevertheless, you learned about the ShapeSheet and how you can manipulate geometry to behave more intelligently, add custom actions to shapes, and link text to Shape Data.
You saw how to generate VBA code using the macro recorder, extend the utility of shapes by creating subroutines that manipulate them, and call the code from shapes themselves.
Finally, this chapter discussed opportunities for deployment, including distributing shapes with stencils and templates, and the issues that come up with VBA code stored in documents.
13.58.113.193