Consulting

Results 1 to 2 of 2

Thread: Run VBA macros in Visio Viewer.

  1. #1

    Run VBA macros in Visio Viewer.

    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?

    Thanks.

  2. #2
    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
       endif
    next i
    Last edited by Aussiebear; 04-12-2023 at 04:21 PM. Reason: Adjusted the code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •