• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

bVisual

  • Home
  • Services
    • How Visio smartness can help your business
    • Visio visual in Power BI
    • Visio Consulting Services
    • Visio Bureau Services
    • Visio Training and Support Services
  • Products
    • Visio Shape Report Converter
    • SS Plus
    • LayerManager
    • visViewer
    • Metro Icons
    • Rules Tools for Visio
    • The Visio 2010 Sessions App
    • Multi-Language Text for Visio
    • Document Imager for Visio
    • multiSelect for Visio
    • pdSelect for Visio
  • Case Studies
    • Case studies overview
    • Visualizing Construction Project Schedules
    • Visio Online Business Process Mapping
    • Nexans Visio Template
    • CNEE Projects, WorldCom
    • Chase Manhattan Bank
  • News
    • Recent news
    • News archive
  • Resources
    • Articles➡
      • ShapeSheet Functions A-Z
      • Comparing Visio for the Web and Desktop
      • Customising Visio Shapes for the Web App
      • Key differences between the Visio desktop and web apps
      • Using the Visio Data Visualizer in Excel
      • Using Visio in Teams
      • Creating Visio Tabs and Apps for Teams with SharePoint Framework (SPFx)
      • Designing Power Automate Flows with Microsoft Visio
      • Innovative uses of Visio Lists
    • Webcasts ➡
      • Visio in Organizations
      • My session and other Visio sessions at MSIgnite 2019
      • Power up your Visio diagrams
      • Vision up your Visio diagrams
      • The Visio 2010 MVP Sessions
    • Visio Web Learning Resources
    • Books➡
      • Mastering Data Visualization with Microsoft Visio
      • Microsoft Visio Business Process Diagramming and Validation
      • Visualizing Information with Microsoft Visio
  • Blog
    • Browse blog articles
    • Visio Power BI articles
    • Visio for Web articles
    • A history of messaging and encryption
  • About us
    • About bVisual
    • Testimonials
    • Bio of David Parker
    • Contact Us
    • Website Privacy Policy
    • Website terms and conditions
    • Ariba Network
You are here: Home / Coding / VBA / Bi-directional Labels on Off-Page Grid References

Published on November 10, 2020 by David Parker

Bi-directional Labels on Off-Page Grid References

I have previously written about using off-page references and labelled page grids in Visio, see A Page Grid with Labels and Page Grids and Off Page References, however a reader pointed out that the label on the Off-Page Reference shape is duplicated on both ends. This is not always ideal, however it is all I could do using just ShapeSheet formulas alone. So, in this article, I show how a VBA macro can enhance the reciprocal labels on the twin Off-Page Reference shapes, and they automatically update if either end is moved between grids. This is especially useful in electrical wiring diagrams, but the principal can be adapted for other purposes.

  • Follow Link to Second Page-C7
  • Follow to Third Page-D1
  • Follow Link to First Page-A4
  • Follow Link to First Page-C3

My previous articles explain that the Off-page reference shape uses the OPC add-on, and contains a slightly modified version in of this master, along with a custom GridLabel and GridLines masters. I have created a more up-to-date version as Page Grid With OPC.vsdx for downloading.

If this document is placed in OneDrive or SharePoint Online, then it can be edited. The Off-page reference shapes can be moved, and the label of twin shapes will be automatically updated with the grid reference of its destination. The hyperlinks can be followed with the CTRL-Click on each Off-page Reference shape.

In Visio desktop, the Off-page reference shapes can be double-clicked, and the destination twin shape will also be selected. This is because the OPC add-on is built-in to Visio desktop, whereas currently the hyperlink navigation only opens the target page.

Running the Enhance OPCs macro

All of the VBA code is in the Enhanced OPC.vssm macro-enabled stencil, which can be downloaded and placed into the My Shapes folder. It will then be available to open in the Visio UI. It contains just one master, Enhance OPCs, which can be dragged and dropped on to any page in the above Visio document. This can be done anytime after adding more of the Off-page reference shapes available from the Document Stencil or the Basic Flowchart stencil, as it will enhance each of the instances.

Drag and Drop the Enhance OPCs shape

The code iterates through each page, and selects all instances of the Off-page reference shape. It then checks that the User.OPCDPageID cell exists because this contains the unique ID of the destination page. This is automatically entered by the Microsoft OPC add-on, as is the unique ID of the destination shape in the User.OPCDShapeID cell.

This existing ShapeSheet formula, =RUNADDONWARGS(“OPC”,”/CMD=3″), in the TheText cell calls this OPC add-on and updates the text of the twin shape whenever the text is changed. This is why the existing functionality has identical text in each of the twin shapes, so the macro removes this, and instead, inserts a a formula into the User.visEquivTitle.Prompt cell. The previous articles used the User.visEquivTitle.Value cell to store the row and column label text, so all that this macro does is create a reference to this call in the twin shape:

"=Pages[" & trgtPage & "]!Sheet." & trgtShape.ID & "!User.visEquivTitle"

This cell reference can then be inserted into the text block of the shape, and it will thus be automatically updated if the destination shape is moved within its page to a different grid reference.

I needed two helper functions, GetShape and GetMasterU, before using them in the EnhanceTheOPCs function.

GetShape function

This function returns the shape specified with the unique IDs of the destination page and shape, or nothing if it does not exist.

Private Function GetShape(ByVal pageUID As String, ByVal shapeUID As String) As Visio.Shape
On Error GoTo errHandler
Dim pag As Visio.Page
Dim shp As Visio.Shape
    For Each pag In ActiveDocument.Pages
        If pag.PageSheet.UniqueID(Visio.VisUniqueIDArgs.visGetOrMakeGUID) = pageUID Then
            Set shp = pag.Shapes(shapeUID)
            Set GetShape = shp
            GoTo exitHere
        End If
    Next pag

exitHere:
    Exit Function
errHandler:
    'Not found
    Resume exitHere
End Function

GetMasterU function

This function returns the master in the active document of the passed in master name, or nothing if it does not exist.

Public Function GetMasterU(ByVal masterName As String) As Visio.Master
    If Len(masterName) = 0 Then
        Exit Function
    End If
Dim mst As Visio.Master

    For Each mst In Visio.ActiveDocument.Masters
        If UCase(mst.NameU) = UCase(masterName) Then
            Set GetMasterU = mst
            Exit Function
        End If
    Next

    Set GetMasterU = Nothing
End Function

EnhanceTheOPCs function

This sub-function enhances all of the instances of the specified master

Public Sub EnhanceTheOPCs()
On Error GoTo errHandler
    Const MSTR As String = "Off-page reference"

Dim mst As Visio.Master
    Set mst = GetMasterU(MSTR)
    If mst Is Nothing Then
        GoTo exitHere
    End If
Dim pag As Visio.Page
Dim sel As Visio.Selection
Dim shp As Visio.Shape

Dim trgtPageUID As String
Dim trgtShapeUID As String

Dim trgtPage As Visio.Page
Dim trgtShape As Visio.Shape

Dim chars As Visio.Characters

    For Each pag In ActiveDocument.Pages
        Set sel = pag.CreateSelection(visSelTypeByMaster, 0, mst)
        For Each shp In sel
            If shp.CellExistsU("User.OPCDPageID", Visio.VisExistsFlags.visExistsAnywhere) <> 0 Then
                trgtPageUID = shp.CellsU("User.OPCDPageID").ResultStr("")
                trgtShapeUID = shp.CellsU("User.OPCDShapeID").ResultStr("")
                If Len(trgtPageUID) = 38 And Len(trgtShapeUID) = 38 Then
                    Set trgtShape = GetShape(trgtPageUID, trgtShapeUID)
                    If Not trgtShape Is Nothing Then
                        Set trgtPage = trgtShape.ContainingPage
                        If shp.CellExistsU("User.visEquivTitle", Visio.VisExistsFlags.visExistsAnywhere) Then

                            shp.CellsU("Hyperlink.OffPageConnector.SubAddress").FormulaU = "=""" & trgtPage.Name & "/" & trgtShape.Name & """"
                            shp.CellsU("Hyperlink.OffPageConnector.Description").FormulaU = "=User.visEquivTitle"
                            'Remove the existing formula =RUNADDONWARGS("OPC","/CMD=3")
                            shp.CellsU("TheText").FormulaU = "=0"
                            
                            shp.CellsU("User.visEquivTitle.Prompt").FormulaU = "=Pages[" & trgtPage & "]!Sheet." & trgtShape.ID & "!User.visEquivTitle"
                            
                            Set chars = shp.Characters
                            chars.Delete
                            chars.Begin = 0
                            chars.End = 1
                            chars.AddCustomFieldU "User.visEquivTitle.Prompt", visFmtNumGenNoUnits
                        End If
                    End If
                End If
            End If
            
        Next shp
    Next pag
    

exitHere:
    Exit Sub
errHandler:
    MsgBox Err.description, vbExclamation, "EnhanceTheOPCs"
    Resume exitHere
End Sub

Further reading

Making the Off-Page Reference Hyperlink URL Safe
Getting the Name of Glued Connection Points

Pushing Data Visualizer in Visio beyond its limits

My last post was about some of the lessons learnt when trying to push Data Visualizer to its limits, but this one has some ways of overcoming these limitations. The main lesson learnt is that DV binds the shapes within the DV container shape, CFF Data Visualizer, and controls some of the ShapeSheet cells that…

Pushing Data Visualizer in Visio to the limits!

Regular readers of my blog will know that I like to use the Data Visualizer (DV) in Visio Plan 2, but I recently tried to help a user who really decided to push it to the limits. In this scenario, there were multiple connections, but with different labels, being created between the same flowchart shapes,…

Setting Theme defaults in Visio

I was recently asked how to change the default font size and line weight in Visio, and then saw then many others are asking the same sort of question. I found one reasonable answer suggesting that you should create a new document from your required template, then edit the Styles to suit, and then save…

Taking Visio Actions Rows to the limit

I recently (re-)discovered that there is a limit to the number of Actions section rows that will be evaluated for display on the right mouse menu of a Visio shape. I have not hit a limit (yet) for the number of rows that can be added to the Actions section … so why is there…

A Multi-Time Zone Clock for Visio

I wrote a post about making a clock face in Visio fifteen years ago, but a reader recently asked about displaying multiple time zones. Well, I have previously written about time zones in Visio, so I accepted the challenge to improve upon my earlier work. (more…)

Update any Visio ShapeSheet cell with External Data

When Microsoft introduced a new way of linking external data to Visio shapes in 2007, I initially bemoaned the inability to update anything but Shape Data row values, unlike the old database add-on that I had been using for 10 years. The new method, though, has many advantages over the old way, not least that…

Related

Filed Under: Hyperlinks, ShapeSheet Formulas, VBA, Visio Tagged With: Grids, Off-page reference, OPC, ShapeSheet Functions, VBA, Visio

About David Parker

David Parker has 25 years' experience of providing data visualization solutions to companies around the globe. He is a Microsoft MVP and Visio expert.

Reader Interactions

Comments

  1. John says

    November 23, 2022 at 9:07 am

    Thank you so much for this! Is there a way to use the page number instead of the page name for this?

    Reply
    • John says

      November 23, 2022 at 12:29 pm

      Whoops! Figured out my problem. An existing document stencil was overwriting my OPC text when I placed a new one from my stencil group. Thank you!

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

  • LinkedIn
  • Twitter

Recent Posts

  • Update to LayerManager add-in for non-English users
  • Pushing Data Visualizer in Visio beyond its limits
  • Pushing Data Visualizer in Visio to the limits!
  • Teams Tuesday Podcast Recording about Visio
  • Linking Data to Visio Shapes in Code

Categories

Tags

Accessibility Add-Ins Connectors Containers Data Export Data Graphics Data Import Data Visualizer Educational Excel GraphDatabase Hyperlinks Icon Sets JavaScript Layers Legend Link Data to Shapes Lists MSIgnite MVP Office365 Org Chart PowerApps PowerBI PowerQuery Processes Shape Data Shape Design ShapeSheet ShapeSheet Functions SharePoint 2013 SQL Teams Themes Validation VBA Video Visio Visio 2007 Visio 2013 Visio for the Web Visio Online Visio Services Visio Viewer Webinar

Footer

bVisual Profile

The UK-based independent Visio consultancy with a worldwide reach. We have over 25 years experience of providing data visualization solutions to companies around the globe.

Learn more about bVisual

  • LinkedIn
  • Twitter

Search this website

Recent posts

  • Update to LayerManager add-in for non-English users
  • Pushing Data Visualizer in Visio beyond its limits
  • Pushing Data Visualizer in Visio to the limits!
  • Teams Tuesday Podcast Recording about Visio
  • Linking Data to Visio Shapes in Code

Copyright © 2023 · Executive Pro on Genesis Framework · WordPress · Log in