I have a few Google alerts set up to let me know if the word Visio is mentioned on the internet. I am always interested in new stencils for Visio and this has proven an effective way of finding them. Most of the time, the hit has nothing to do with the product Visio or it was a link to a download site for Visio or one of the books written about Visio. Today was slightly different, there was a link to a blog that said "In Visio 2007, i want to change skin color, but I don't know the formula's - does anybody know?", but no answer.
Thanks to the Visio devs, it is quite easy (almost). They were nice enough to provide a User cell (similar to a custom property/shape data, but hidden) called User.SkinColor where you can set the skin colour. For the Accounting shape in the Workflow stencil of Visio 2007, that value is HSL(21,165,128). HSL stands for Hue, Saturation and Luminesance and is a similar means for setting a colour as RGB.
Of course, the tricky bit is working out what HSL values correspond to different skin tones and assigning a politcally correct name to it. I can understand why the Visio devs would not want to spend days arguing over the correct skin tone of someone from Redmond.
The use of the HSL function is a good choice because it provides a good range of skin tones by just modifying the value for luminesance. So it would be possible to create a simple piece of VBA code to display a slider that would change the user cell User,SkinColor of the selected shape (or shapes) from a value from 0 to 240.
John... Visio MVP
Debra Dalgleish, one of the Excel MVPs mentioned an old episode of the Computer Chronicles on Facebook and provided a link.
It did not take me long to find an appropriate link for the Visio crowd. The show is about Windows 95 and OS2, but at 16:50 to 20:00 is an intro to Visio 3.1
http://www.archive.org/details/Windows4
Nice shirt Ted!
One of the posters in the newsgroup was asking about providing a revision date on each page of a Visio document and this is what I came up with. The only dates that are associated with a Visio drawing are done at the document level, so another apporach is necessary.
To create a date stamp at the page level, add a custom property/Shape Data to the pagesheet for each page. This property can then be changed automatically when the page is altered. Since the property is updated automatically, the property will also be created if it does not exist.
Private Sub Document_BeforeSelectionDelete(ByVal Selection As IVSelection)
UpdateDateReviewed
End Sub
Private Sub Document_PageAdded(ByVal Page As IVPage)
UpdateDateReviewed
End Sub
Private Sub Document_ShapeAdded(ByVal Shape As IVShape)
UpdateDateReviewed
End Sub
Private Sub Document_ShapeExitedTextEdit(ByVal Shape As IVShape)
UpdateDateReviewed
End Sub
Sub UpdateDateReviewed()
Dim vsoShape As Visio.Shape
Dim intPropRow As Integer
Set vsoShape = ActivePage.PageSheet
If vsoShape.CellExists("Prop.DateRevised", False) = False Then
intPropRow = vsoShape.AddRow(visSectionProp, visRowLast, visTagDefault)
vsoShape.CellsSRC(visSectionProp, intPropRow, visCustPropsLabel).FormulaU = """DateRevised"""
vsoShape.CellsSRC(visSectionProp, intPropRow, visCustPropsValue).RowNameU = "DateRevised"
vsoShape.CellsSRC(visSectionProp, intPropRow, visCustPropsType).FormulaU = "5"
vsoShape.CellsSRC(visSectionProp, intPropRow, visCustPropsFormat).FormulaU = ""
vsoShape.CellsSRC(visSectionProp, intPropRow, visCustPropsPrompt).FormulaU = ""
vsoShape.CellsSRC(visSectionProp, intPropRow, visCustPropsValue).FormulaU = ""
End If
vsoShape.Cells("Prop.DateRevised") = Format(Now(), "00000.00000")
End Sub
One thing that got me hooked on Visio from the beginning was that you were not limited to the shapes that were supplied by the product, You could create shapes from scratch, modify existing shapes or wrap an image from any source into a Visio shape. So, I am always on the hunt for new shapes that are available on the internet.
Recently, I came across a set of well made shapes and was able to get in touch with the creator. Though the shapes looked good, they did not have any of the smarts that can be associated with Visio shapes. The Visio shapes were just foreign images that could not be changed or coloured. The shapes were originally created in Adobe Illustrator and imported into Visio. I tried using other export options from Illustrator, but none allowed me to ungroup the shapes in Visio so the shape can be disected into individual elements that be recombined.
Thanks to Enric Mañas, a PowerPoint MVP, I found out that it is possible to disect the shape by using PowerPoint. The file needs to be first saved as an EPS in Illustrator. The EPS file is then inserted into a new PowerPoint slide and then saved as a WMF file. The WMF file is then inserted in to a Visio drawing and this new shape can then be ungrouped.
So if you need to manipulate a shape created in Adobe Illustrator, use PowerPoint to convert an EPS file to a WMF file.
Visio has a problem with duplex printing.
If you ask for multiple copies while duplex printing, you only get one copy. This is rather annoying, but the problem is not with duplex printing. The issue is with the collate option. You can duplex print a Visio document and request mutiple copies and your document will print the correct number of pages, only if you do not select collate. Of course, the pile of paper generated is useless. What is printed on the front and back of the first piece of paper is two copies of page 1.
There is a knowledge based article http://support.microsoft.com/kb/924114 but that indicates that the issue is that collate is not checked. The only workable solution is to set the copies to 1. Sounds like a Henry Ford answer. You can get any colour you like, as long as it is black. You can print as many copies as you like as long as the number of copies is 1.
Have you ever wanted to add an area around a group of shapes? For example, you want to identify a group of computers that belong to the draughting department? Simple, you just draw a shape around a group of shapes, but the problem arises when you want to expand or shrink the shape that encloses the group of shapes.
With Visio 2010, is a new concept called containers that will automatically stretch or shrink depending on the shapes contained.
Though not directly Visio related, I have been playing with converting the MSO shapes used in Word, Excel, PowerPoint and Publisher into Visio shapes. The shapes are similar to Visio shapes and include control handles. So far I have created a Visio stencil for the shapes and have added some of the smarts into the shapes. I have been able to create Visio drawings from MSO shapes in PowerPoint and transfer some of the settings for the shapes. The fun has been getting around the MSO*mixed types. (It basically indicates that you have to go down another path to search for your information)
One thing I noticed is that five of the MSO shapes return the wrong shape type. They are:
|
110
|
msoShapeLineCallout2
|
109
|
msoShapeLineCallout1
|
|
117
|
msoShapeLineCallout1NoBorder
|
113
|
msoShapeLineCallout1AccentBar
|
|
118
|
msoShapeLineCallout2NoBorder
|
113
|
msoShapeLineCallout1AccentBar
|
|
121
|
msoShapeLineCallout1BorderandAccentBar
|
109
|
msoShapeLineCallout1
|
|
137
|
msoShapeBalloon
|
106
|
msoShapeRoundedRectangularCallout
|
With Office 2007, the main apps introduced the ribbon and with Office 2010, Office introduced the ability to customize the ribbon. Since the ribbon was a major shift in the UI experience, it made sense that only the key apps should "test the waters" and the other apps should wait till the next release. It was basically a "too many cooks spoil the broth" scenerio.
With Visio 2010, Visio acquired the Ribbon AND ribbon customization. One problem with menus in Visio 2007 was their placement was not optomized and it was possible to leave gaps. So the introduction of the ribbon meant a better placement of the buttons and only displaying the relevant ones. (Of course, relevancy is subject to interpretation)
With the introduction of the ribbon, there were some major changes in the UI. One noticable one is the removal of the "Use Developer Mode" checkbox in the Options menu. The user can now directly customize the ribbon to enable the buttons that were added by the old "Use Developer Mode" option checkbox.
There is an alternate way to get to code. On the View tab, the last group is Macros. You can then access or create VBA macros.
A recent post in the newsgroups asked about a stencil for IVR. IVR - Interactive Voice Response - is the system we have known to love as the automated telephone system - Press 1 for customer service rep, 2 for sales and so on. A VRU Voice Response Unit is the computer that runs the software.
In a past life I maintained an IVR system for a bank and of course, documented it with Visio. Except for a few specialized shapes, most of the shapes were from the flowchart stencil. With Visio 2007, some of the workflow shapes could have come in handy. So the specialized shapes I used were:
A Decision Box - This box contained the prompt presented the user and ten connection points to the possible responses ( 0 to 9)
A CSR shape - Customer Service Rep (aka operator) This was just a piece of clipart of an operator with a headset. Since this was a common destination when the user pressed 0, it was placed in many places on the flowchart. (I wonder if I can talk Visio Guy into creating one of his people shapes for this?).
A manframe shape - The actual VRU was an OS2 box, but all the data was stored on a mainframe.
A fax machine - One of the features we added was the ability to have your bank statement faxed to your fax machine.
So I will try and put a VRU / IVR stencil together and post it on the Visio MVPS website. If anyone can come up with any additional shapes that would be useful for the stencil, let me know.
It has been almost two years since I blogged, so it is time to dust off the blog.
Today in the newsgroups someone asked about using the Polar Array VBA sample from the Visio MVP website, but rather than place a specific shapes multiple times, arrange the shapes that are selected.
As usual, the original credit goes to Chris
Sub PolarArray()
' by Chris Roth
Dim shp As Visio.Shape, shpObj As Visio.Shape, celObj As Visio.Cell
Dim iNum As Integer, i As Integer
Dim dRad As Double, dAngStart As Double, dAng As Double
Dim x As Double, y As Double
Dim VsoSelect As Visio.Selection
Dim VsoShape As Visio.Shape
' obtain the shape to be distributed
Set shp = Visio.ActiveWindow.Selection(1)
Const PI = 3.14159265358
Set VsoSelect = Visio.ActiveWindow.Selection
If VsoSelect.Count > 1 Then
iNum = VsoSelect.Count
dRad = InputBox("Enter the radius for the polar array in inches:", "Polar Array")
dAngStart = InputBox("Enter the first angle in degrees (0 deg = 3 o'clock):", "Polar Array")
dAngStart = dAngStart * PI / 180 'Convert to radians
dAng = 2 * PI / iNum
For i = 1 To iNum
x = dRad * Cos(dAngStart + dAng * (i - 1)) + 4.25
y = dRad * Sin(dAngStart + dAng * (i - 1)) + 5.5
Set VsoShape = VsoSelect(i)
' Set shpObj = Visio.ActivePage.Drop(shp, x, y)
VsoShape.Cells("Pinx").Formula = x
VsoShape.Cells("piny").Formula = y
' rotate the shape - This only makes sense if this is a group of chairs around a table
' Set celObj = VsoShape.Cells("Angle")
' celObj.Formula = Str(Int((i - 1) * 360 / iNum)) + "deg."
Next i
Else ' if only one shape is selected, then
iNum = InputBox("Enter the number of items in the array:", "Polar Array")
dRad = InputBox("Enter the radius for the polar array in inches:", "Polar Array")
dAngStart = InputBox("Enter the first angle in degrees (0 deg = 3 o'clock):", "Polar Array")
dAngStart = dAngStart * PI / 180 'Convert to radians
dAng = 2 * PI / iNum
For i = 1 To iNum
x = dRad * Cos(dAngStart + dAng * (i - 1)) + 4.25
y = dRad * Sin(dAngStart + dAng * (i - 1)) + 5.5
Set shpObj = Visio.ActivePage.Drop(shp, x, y)
shpObj.Text = i
' rotate the shape
Set celObj = shpObj.Cells("Angle")
celObj.Formula = Str(Int((i - 1) * 360 / iNum)) + "deg."
Next i
End If
End Sub
For a long time Visio has supported stencils and templates in two different measurement system; Imperial (US) and Metric. Each template had a US version and a Metric version. So why two templates? The US templates were in in, ft, yds and the other imperial units and the Metric templates were in mm, cm, m and the other metric units. There was also an isue of the physical page size; Some of the standard sizes for the US are letter, legal and tabloild while the metric sizes were the A format sizes like A3 and A4.
So is it possible to have a single template that will handle both Imperial and Metric units and paper sizes? Yes, with a few minor changes, you can combine both units.
One method to do this is to add a user defined cell to the document and use that variable to determine the system to use. To add a document level user defined cell, right click the top entry in the Drawing Explorer and select Show ShapeSheet or right click the drawing surface outside the drawing and hold the shift key while selecting Show ShapeSheet. If you do not hold down the shift key, you will get the shapesheet for the page. Add a rowl to the User Defined Cells section and name it something like UseMetric. Use a value of 0 for Metric units and non zero for Imperial units.
On each page set the PageHeight, PageWidth, PageScale and DrawingScale with a formula like.
For Page Width set the content to: = IF(TheDoc!User.UseMetric=0,210mm,8.5in)
As you change the value of UseMetric, the PageWidth (and other qualities) will reflect the selected units.
This will give you a document that will switch between a letter size drawing in inches and an A4 drawing in mm.
The next step would be to add unit agnostic formulas to your shapes.
If you already have background pages created in Imperial units and metric units, rather than trying to merge the two with formulas based on TheDoc!User.UseMetric, combine the two background pages by applying each page to a layer and use TheDoc!User.UseMetric to control the visibilty of each layer.
Visio does provide an option for printing shapesheets but it is wordy. In the past I have used Excel to sort and manipulate the information, but this is time consuming and really does not give me everything I want. One thing that was not easy to do was to find out whether a shapesheet was part of a group and if so, which group it belonged to. Being Visio, this is not a big problem. The object model is exposed and it is possible to write your own version of the shapesheet print Add-in with a routine to show the lineage of a shapesheet.
Given a Visio shape, this function will return a string that lists its' ancestors.
Private Function Heritage(shpObj As Visio.Shape) As String
Dim Finished As Boolean
Dim tmpName As String
Dim tmpString As String
tmpName = shpObj.Name
tmpString = tmpName
Finished = False
Do While Not Finished
If ActivePage.Shapes(tmpName).Parent.Type = visTypeGroup Then
tmpName = ActivePage.Shapes(tmpName).Parent.Name
tmpString = tmpName + " " + tmpString
Else
Finished = True
End If
Loop
Heritage = tmpString
End Function
This sample code will eventually make it's way over to http://visio.mvps.org/VBA.htm
When I try to create Visio shapes from a sample image, I import the image into Visio and stretch it so it matches the scale of the drawing. I can then use the dimension shapes to "measure" the image.
Recently I came across a collection of shapes that had similar profiles, but the proportions varied. I needed a new kind of measuring tool, one that would display percentages. With Visio, this is relatively easy.
The shape is a simple line with a control handle with a user defined field set to "=GUARD(Controls.Point/Width)". The text field for the line contains the user defined field. The line is strectched across the distance that needs to be proportioned and the control handle is moved to various positions. The text of the line will show the percentage of the distance that the control handle is at.
I had considered constraining the control handle to the line, but the freedom of movement makes it very easy to "measure" irregular shapes.
John... Visio MVP
Over the summer I was asked if it was possible to have some of the reporting lines a different pattern. An interesting idea, but how do you mantain the feature when the Orgchart is imported and exported?
For this feature to work the information had to be stored with the person at the bottom of the reporting relationship. The Custom Properties (Soon to be Shape Data) of each person was preserved over imports and exports and was the ideal location. So once the data was imported into Visio VBA code was run to check each 2d shape for a "Reporting Type" Custom Property and change the line pattern of their reporting line to match.
Sub ChangeReportingLines()
' Display connections on the page
Dim conObj As Visio.Connect
Dim i As Integer
Dim ReportingType As String
Dim vsoPage As Visio.Page
Dim VsoShp As Visio.Shape
For Each vsoPage In ActiveDocument.Pages
For Each VsoShp In vsoPage.Shapes
If Not VsoShp.OneD Then
nrows = VsoShp.RowCount(Visio.visSectionProp)
For i = 0 To nrows - 1
If VsoShp.CellsSRC(Visio.visSectionProp, i, visCustPropsLabel).ResultStr(Visio.visNone) = "ReportingType" Then
ReportingType = VsoShp.CellsSRC(Visio.visSectionProp, i, visCustPropsValue).ResultStr(Visio.visNone)
For Each conObj In VsoShp.FromConnects
If conObj.FromPart = visEnd Then
Debug.Print "change to --> "; ReportingType
Select Case ReportingType
Case "Dotted"
conObj.FromSheet.CellsSRC(visSectionObject, visRowLine, visLinePattern).FormulaU = "3"
Case "Dashed"
conObj.FromSheet.CellsSRC(visSectionObject, visRowLine, visLinePattern).FormulaU = "2"
Case Else
Debug.Print ReportingType
End Select
End If
Next conObj
End If
Next i
End If
Next VsoShp
Next vsoPage
End Sub
This can be taken further by trapping any changes to the line pattern through the UI and updating the Custom Property to match.
John... Visio MVP
It has been a long standing fact that though there were several Visio file tpes; stencils, drawing, templates and workspaces, there was a only one Visio file format. Several versions ago, a new file format crept into the Visio file format. Visio added a reporting facility that used a seperate file to store information about how to create the report.
About the same time, Visio gave the Visio user the oppurtunity to save Visio drawings in XML format. So, the information in the Visio Report Definition (VRD) files is also stored in XML format. For Visio 2003, the third version of the VRD, schemas were created. (schemas-microsoft-com:office:visio:reportdefinition).
The VRD file is divided into several sections. The first section sets basic information for the report, the title, the description.
The second section, a collection of <VisioRptDefField>s, describes the fields to be used, the column headers and the order.
The third section, a collection of <VisioRptDefFilter>s, describes the filters that would apply to seect the information for the report.
The fourth section, <VisioRptDefGroup>, describes how the records are grouped.
The fifth section, a collection of <VisioRptDefSort>s, describe how the information is sorted.
For Visio 2007, there are no new or deleted reports and the only changes are very, very minor corrections to the reports' description.
So what is the point of knowing this? I have yet to see a request in the Visio newsgroups for automating report creation, but creating or modifying XML will be far easier than trying to control the wizard by Sendkey.
John... Visio MVP
When dropping a border or title shape on a page, it automatically stretches to fit the page, but if you look at the shapesheet for the dropped shape, Width and Height are fixed. How do they do that?
The trick is that the shape on the stencil has an EventDrop cell that tells Visio to set the values of Width, Height, PinX and PinY to fixed values when the shape is dropped on a page. It also tells Visio to clear the EventDrop cell so the process can not be repeated by the copy.
You can find samples of these shapes by looking in the "Background" "Border and Titles" stencils. When you look ath these shapes, you will find that these shapes define their size based on the page size using the following formula:
Width =ThePage!PageWidth-4*User.PageMargin
Height=ThePage!PageHeight-4*User.PageMargin
PinX=ThePage!PageWidth*0.5
PinY=ThePage!PageHeight*0.5
The value for the PageMargin row in the User Section is a bit involved to repeat here, but it sets the margin off the shape based on the scaling factors in use.
The EventDrop cell uses SETF and GETF to assign the initial formula to the four cells and then replace it with the formulas value. I have broken the formula into its' five components to make it more readable. In reality, the formula in the EventDrop cell below is one long string.
=SETF(GetRef(Width),ThePage!PageWidth-4*User.PageMargin)
+SETF(GetRef(Height),ThePage!PageHeight-4*User.PageMargin)
+SETF(GetRef(PinX),ThePage!PageWidth*0.5)
+SETF(GetRef(PinY),ThePage!PageHeight*0.5)
+SETF("EventDrop",0)
The final SETF clears the EventDrop cell.
A similar method is used for Background pages, but the formulas are not cleared
Width =GUARD(ThePage!PageWidth)
Height=GUARD(ThePage!PageHeight)
PinX=GUARD(Width/2)
PinY=GUARD(Height/2)
Unlike the Borders and Titles shapes, the Background shape needs to run an add-on to place the shape. The EventDrop cell contains:
=RUNADDON("Make Background")+SETF("EventDrop",0)
The "Make Background" is a Private add-on which will create a background page called VBackground, place and resize the shape and then add the background page reference to the foreground page.
John... Visio MVP
To create a circular arc in a shapesheet's Geometry section, requires the specification of where the arc ends and a cell called "A" that holds the measurement of how much the arc differs from a straight line between the end points of the arc. The deflection indicates how much the arc bows. It is possible to fragment a circular shape to get an idea of a value of "A", but it is a value not a formula.
So what is a formula to describe the content of the "A" cell? To determine a formula, you need to revisit your grade school trigonometry notes. A line that connects two points a circle is called a chord and has a few special properties. The largest chord passes through the center of the circle and is called the diameter. A triangle formed by the chord and the center of the circle forms an Isosceles triangle. The angles at either end of the chord are identical. If you use the half way point on the chord, call it B, to bisect the triangle through the center of the circle, call it C, you end up with two identical right angles triangles.
The length from B to C divided by the hypotenuse of the right angle triangle is the sine of the angle of the right angle triangle at the center of the circle. In this case, the hypotenuse is the radius of the circle and the angle is half the value of the angle formd by Isosceles triangle.
So the length of BC is: Radius x Cosine (angle/2).
So the formula for cell "A" is: Radius - Radius times Cosine (angle/2) or Radius (1 - Cosine(angle/2))
John... Visio MVP
About a week ago I was asked if it was possible to save the information from a hand drawing Orgchart (one done without the wizard). The simple answer was yes, but with a few caveats. It would not be an easy task to extract all the information from the diagram.
Visio allows the user two views of their diagram; the one most people are familiar with is the one that appears on the screen or the printed page; the second is what a program can "see" of the drawing through automation. What may appear logical in the diagram, may not actually be the true representation. For example, the ethernet shape in the network stencil has only eight connection points. By dropping a second ethernet shape on top of the first, it appears that there is a single ethernet shape with sixteen connection points. From the automation side, there would still be two seperate ethernet shapes.
So here are some guidelines for creating Visio diagrams, not necessarily orgcharts, so that they are more automation friendly.
The first suggestion is to standardize on the shapes. It is a lot easier for an automation routine to understand a drawing if all similar shapes have the same master. For example, most diagrams contain extra shapes in addition to the ones used for the connected diagram. There may be legends, title blocks, side comments and company identifiers. Thses shapes can be identified by the fact that they are unconnected, but it would be easier if the automation routine was looking for specific shapes.
Background pages would reduce the number of unconnected shapes on the foreground pages. It would add consistency to the drawings by making sure that common information appears in the same location on each page.
If you are creating your own shapes, keep them as simple as possible. Do not avoid grouped shapes, but make sure they are necessary. Each group shape is a collection of shapes and once one is found, this new collection of shapes has to be processed. Most shape features (connection points, custom properties and various geometry sections) can be contained in a single shape. The only real need for grouping shapes is to add secondary colours, line formats or text blocks.
One of the caveats on the drawing I saw was how was it possible to extract the name and position as seperate items from the OrgChart. Luckily in the example, though the two pieces of information are in the same text block, each had a different format (One was in bold). Using the Characters collection in Visio makes it possible to seperate the two strings. If starting from scratch, it would have been easier to use custom properties and reference the custom properties from the text block.
When connecting shapes, make sure the connection goes to the connection point on the logical shape. I have seen some shapes that appear to connected, but in fact, the free end of it's connecting line is just sitting near one of the other lines. In another example, a group of vertically stacked individuals appear to be connected to a supervisor, but in fact each shape is connected to the shape above it rather than to the logical shape, the supervisor.
Connecting lines are 1-d shapes and have a beginning and an end. Be consistent as to whether the supervisor is at the beginning or the end of the line. I'll leave it to the academics as to which one it should be.
Finally, with the release of Visio 2003, came Visio's most useful tool for development; the macro recorder. By clicking the record button it is possible to quickly see how various Visio tasks can be translated into VBA. The Help file that comes with Visio is useful for explaining the details of a command, but there is not enough examples explaining how to string several commands together, the macro recorder fills in this gap.
For example, to simply answer the question; "How do you create two shapes and connect them together using VBA?" The macro recorder will generate the following macro.
Sub Macro1()
Application.ActiveWindow.Page.DrawRectangle 1#, 10#, 2#, 9#
Dim vsoCharacters1 As Visio.Characters
Set vsoCharacters1 = Application.ActiveWindow.Page.Shapes.ItemFromID(1).Characters
vsoCharacters1.Begin = 0
vsoCharacters1.End = 0
vsoCharacters1.Text = "John"
Application.ActiveWindow.Page.DrawRectangle 3#, 10#, 4#, 9#
Dim vsoCharacters2 As Visio.Characters
Set vsoCharacters2 = Application.ActiveWindow.Page.Shapes.ItemFromID(2).Characters
vsoCharacters2.Begin = 0
vsoCharacters2.End = 0
vsoCharacters2.Text = "Mary"
Dim UndoScopeID3 As Long
UndoScopeID3 = Application.BeginUndoScope("Drop On Page")
Application.Windows.ItemEx("atest.vsd").Activate
Application.ActiveWindow.Page.Drop Application.Documents.Item("C:\DOCUME~1\John\MYDOCU~1\VISIOC~1\atest.vsd").Masters.ItemU("Dynamic connector"), 0#, 0#
Dim vsoCell1 As Visio.Cell
Dim vsoCell2 As Visio.Cell
Set vsoCell1 = Application.ActiveWindow.Page.Shapes.ItemFromID(3).CellsU("BeginX")
Set vsoCell2 = Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(1, 1, 0)
vsoCell1.GlueTo vsoCell2
Set vsoCell1 = Application.ActiveWindow.Page.Shapes.ItemFromID(3).CellsU("EndX")
Set vsoCell2 = Application.ActiveWindow.Page.Shapes.ItemFromID(2).CellsSRC(1, 1, 0)
vsoCell1.GlueTo vsoCell2
Application.EndUndoScope UndoScopeID3, True
End Sub
That sure looks like a mouthful, but it can quickly reduced to a more manage size by a few simple edits.
The macro recorder will record the actions taken and the extra code required to undo the changes. This extra code is easily identified and can be quickly removed. Each block of undo code uses a variable with a name like UndoScopeIDn, where n is a number that gets incremented for each undo bloc. Each block contains three commands; a Dim, Application.BeginUndoScope and a Application.EndUndoScope statement. These statements can be removed.
The references to Application.ActiveWindow.Page can be replaced with a reference to ActivePage.
The macro recorder uses the more formal form of Shapes.ItemFromID(1), but this can be simplified to Shapes(1).
For text handling you will probably find something like:
Set vsoCharacters1 = ActivePage.Shapes(1).Characters
vsoCharacters1.Begin = 0
vsoCharacters1.End = 0
vsoCharacters1.Text = "John"
This is useful if you are manipulating the shapes text, but if, as in this case, you are replacing the entire text, this long winded block of text can be replaced with:
ActivePage.Shapes(1).Text = "John"
Now, the macro looks like:
Sub Macro1()
ActivePage.DrawRectangle 1#, 10#, 2#, 9#
ActivePage.Shapes(1).Text = "John"
ActivePage.DrawRectangle 3#, 10#, 4#, 9#
ActivePage.Shapes(2).Text = "Mary"
Application.Windows.ItemEx("atest.vsd").Activate
ActivePage.Drop Application.Documents.Item("C:\DOCUME~1\John\MYDOCU~1\VISIOC~1\atest.vsd").Masters.ItemU("Dynamic connector"), 0#, 0#
Dim vsoCell1 As Visio.Cell
Dim vsoCell2 As Visio.Cell
Set vsoCell1 = ActivePage.Shapes(3).CellsU("BeginX")
Set vsoCell2 = ActivePage.Shapes(1).CellsSRC(1, 1, 0)
vsoCell1.GlueTo vsoCell2
Set vsoCell1 = ActivePage.Shapes(3).CellsU("EndX")
Set vsoCell2 = ActivePage.Shapes(2).CellsSRC(1, 1, 0)
vsoCell1.GlueTo vsoCell2
End Sub
This makes it a lot easier to understand the generated code and relate it back to the information that is provided in the help file.
John... Visio MVP
Thanks to Visio's Mark Nelson for the following tip:
You can add the User.visEquivTitle cell to your shape and provide a string that will display as a tooltip in the web output. The shape must also have at least one custom property for the tooltip to be visible.
Steps:
1) Select the shape in your drawing that you want to add a web tooltip for
2) Go to Window > Show Shapesheet
3) Go to Insert > Section, check User-defined cells and click OK
4) In the newly created section, click on the row name User.Row_1 to select the title of the row
5) Type visEquivTitle and press Enter - you should now see User.visEquivTitle for the row
6) In the Value cell of that row, enter the text you want to display surrounded by quotes (e.g. "Hello World")
7) If you instead want to display the same tooltip as the Shape ScreenTip enter =Comment (no quotes)
8) Go to Insert > Section, check Custom properties and click OK
9) You can fill in the custom property Label and Value if you want this information to be visible
10) If you don't want the custom property to be visible, enter TRUE in the Invisible cell
11) Close the Shapesheet window and repeat for any other shape you like
12) Choose File > Save as Web Page to create the HTML output
As you can see this is a bit involved. The capability was designed more as a developer feature than an end user feature. I recommend tying the Shape ScreenTip to the User cell so that you see the same tooltip in both Visio and the web output. It should also be possible to use Macro Recorder to automate these steps. If your shape has a custom property but does not have the User.visEquivTitle cell, Visio will display the shape's text in a tooltip instead.
More Posts
Next page »