![]() |
![]() ![]() |
|
Gi
us a Wee Peek at Yer David A
EdsonMechanics and History
Note that no path to the .VSL or .EXE is listed. Rather, the .VSL or .EXE must be in Visios search path as set from the Tools > Options Dialog, in the File Paths Tab, on the Add-ons: line. Note that the file paths are semi-colon deliminated. Presuming that you had created a VBA add-on named "Border_Colour", you could call it with the following syntax:
and Visio will be sable to suss out that it is a VBA code item and launch it appropriately. Now heres the slick wee bit o business .. Visios RUNADDON() function can also recognise standard VBA functions as weel as an argument to the function. The next two examples illustrate this making use of the lowly MsgBox VBA function:
Lets have a wee look at the first In this case the RUNADDON() function is calling VBAs MsgBox function a single time and displaying the text "Ive been clicked!" in the message box. Note that the string to be displayed must be enclosed in double-double-quotes in order for the function parser to understand that it is text, and the entire argument to the RUNADDON() function must be a quoted string. This explains the preponderance of double-quotes in the code. The second case calls VBAs MsgBox function five times, and displays the numbers "1", "2", "3", "4", and "5" in each successive message box. Note that each "line" of VBA cone is deliminated here with a colon, and as such three lines of VBA code are executed. Be aware of the limitations of string length in a Visio SmartShape symbols ShapeSheet cell. It is generally about 127 characters. You can programmatically force greater length strings into a cell formula but ANY attempt to access or edit the cell at a later date will truncate it back to the 127 character limit, thereby rendering it, quite, possibly, unusable. A few wee examples
Breakin this doon RUNADDON() is first bindin the variable "shp" to the currently selected shape, that is the first item in the selection collection of the active window. Then a variable "s" is set to the string "Shape Name = " and the concatinated name property of the shape "shp" object. This string is then concatinated with a character string "13", which is a carrage return, and further concatinated with the string "Shape Area = " and the concatinated area-in-internal-units property of the shape "shp" object. Finally this full concatinated string is passed as the argument "s" to the VBA MsgBox() function. Presumin tha the shape is a rectangle 3 inches wide by 2 inches tall and it is the third shape on the current page, the output to the message box would be:
If this same code were to be written in the VBA editor it would look like:
If packin a tha code intae a single line is causin ye tae "fash" (worry, for those of you not of the Celtic persuasion), you can place the individuaql pieces into User Defined Cells and then concatenate them into the EventDoubleClick cell similar to the following:
In this second example, Im going to show you how you can place a large notes field as an attachment to any shape. The user can read an edit the notes as required. To accomplish this you will need to add an Actions section to your ShapeSheet. This will allow the user to "right-click" on the shape and call your functionality. You will be setting the values of both the Menu cell and the Action cell in the Actions section.
The VBA equivalent looks similar to:
Note tha we need tae check the string returned by the input box tae see if it is empty.
If the Cancel button on the Input Box were clicked, then the string returned would be empty. Without this check, the statement:
would clear oot the notes when the Cancel button was clicked. This micht no be what ye had desired, especially if there were lots of notes to the shape, oor the user thought that Cancel just meant that he oor she didnt want to change anything. However, the functionality above negates the possibility of truly deleting the note if that is what the user actually had in mind. To remedy this the following Actions line will clear oot the notes content:
Weel thar ye hae it folk!!! You can now set aboot addin yer ain notes to Visio SmartShapes symbols and additionally, begin tae experiment wi addin your own bits o VBA functionality to your verra smart Visio shapes!!! I want tae thank Chris Roth at Visio for a his weark in researchin an documentin this functionality!!! Ceuid Mile Thanks Chris Laddie!!!!! Till next month, enjoy yer American Thanksgivin, dinnae eat tae much, tak a weel desearved rest, an "Haste ye back." Dave "The Auld Scotsman" Edson
|
|
|
Copyright © 1998-2007 DBM & others | Disclaimer | Privacy | Re-publication | Trademarks | Webmaster | Home |