View Full Version : Run VBA macros in Visio Viewer.

01-22-2009, 09:43 AM
I have a visio file with a diagram of a building and all the computers inside the building. The shapes representing the computers have a list of custom properties with information about the computer they represent.

I also have a search macro, which asks you for information about then highlights all the computer that fit the search criteria.

I'm looking to make a version of this which would allow people to see the visio file, and use the macros I've made, but would not allow them to permanently edit anything.

So far I've looked into using Visio Viewer, which displays everything correctly and allows the user to view a shape's custom properties, while not allowing them to change anything aside from the color of certian things. The only problem is that I can't seem to find a way to run the search macros. Is it possible to run macros in Visio Viewer?

If not, another option that comes to mind is to create a restricted version of the visio file. I know if you create a PDF using Adobe Acrobat, you have the option of restricting what can and can not be edited, and how it can be used. Is it possible to create a similar restricted file in Visio, which will only have access to some selected features?


01-22-2009, 01:17 PM
I just downloaded the Visio Viewer and messed around a bit, but my guess is that you can't execute macros in it. It may be possible to recreate your search macro using the Viewer's object model, which basically just lets you iterate over all the shapes in a drawing by index, and you can pull out custom properties, so that may be enough for you to recreate your search macro.

Basically you'd want to have a function that looks for custom properties on a shape by name:

Function GetCustomPropertyVal(ShapeNum As Long, PropertyName As String) As String
Dim PropIdx As Long
For PropIdx = 1 To ctrViewer.CustomPropertyCount(ShapeNum)
If ctrViewer.CustomPropertyName(ShapeNum, PropIdx) Like PropertyName Then
GetCustomPropertyVal = ctrViewer.CustomPropertyValue(ShapeNum, PropIdx)
Exit Function
End If
Next PropIdx
End Function

so you'd just loop:

for i = 1 to ctrViewer.ShapeCount
if getcustompropertyval( i , "PropertyName" ) <> "" then
' Do something
next i