Automatically linking data in Visio Org Chart to all shapes on all pages

Started by WCTICK, March 03, 2023, 12:44:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

WCTICK

I have a Visio Org Chart that is 70 pages that was created using an Excel file via the import wizard.  I then used the custom import option from the External Data section on the Data tab and specified Position number as the unique identifier to link to the source Excel file.

The import was successful, and the external data is available, but the data link icon is not showing for any of the rows.  I can use the Link Data function to link the data to shapes for a selection or all shapes on the current page.  I want to be able to dynamically change the Org Chart data displayed when the Excel source changes.

Is it possible to link data for all 70 pages using VBA?  Or, is there another way to link the data across the entire Org Chart?


Croc

QuoteIs it possible to link data for all 70 pages using VBA?
Iterate through the pages and use the AutomaticLink method.
Here is a slightly modified example from the documentation.
Public Sub AutomaticLink_Example()
    Dim vsoDataRecordset As Visio.DataRecordset
    Dim vsoSelection As Visio.Selection
    Dim astrColumnNames(1) As String
    Dim alngFieldTypes(1) As Long
    Dim astrFieldNames(1) As String
    Dim alngShapesLinked() As Long
    Dim intCount As Integer
     
    intCount = Visio.ActiveDocument.DataRecordsets.Count
    Set vsoDataRecordset = Visio.ActiveDocument.DataRecordsets(intCount)

    astrColumnNames(0) = "Name"
    alngFieldTypes(0) = Visio.VisAutoLinkFieldTypes.visAutoLinkShapeText
    astrFieldNames(0) = ""

    For Each pg In ActiveDocument.Pages
       ActiveWindow.Page = pg.Name
       ActiveWindow.DeselectAll
       ActiveWindow.SelectAll
   
       Set vsoSelection = ActiveWindow.Selection
       vsoSelection.AutomaticLink vsoDataRecordset.ID, _
                       astrColumnNames, _
                       alngFieldTypes, _
                       astrFieldNames, 0, alngShapesLinked
    Next
End Sub

WCTICK

Great.  Thanks!

Can you point me to the documentation you refer to?


WCTICK

One more question related to this.

The unique identifier field for the Org Chart is namde "Position Number".  There are some vacant positions that don't currently have an employee name associated with them.

When I ran the sample code that sets "Name" as the value of astrColumnNames(0), it links all rows in the external data source that have an employee name listed, but not the ones that are vacant.

I tried to set that variable to "Position Number" - the script ran but didn't link any of the data rows. Would you be able to tell me what I'm doing wrong?


astrColumnNames(0) = "Name"
    alngFieldTypes(0) = Visio.VisAutoLinkFieldTypes.visAutoLinkShapeText
    astrFieldNames(0) = ""

    For Each pg In ActiveDocument.Pages
   
       ActiveWindow.Page = pg.Name
       
       ActiveWindow.DeselectAll
       ActiveWindow.SelectAll
       
   
       Set vsoSelection = ActiveWindow.Selection
       vsoSelection.AutomaticLink vsoDataRecordset.ID, _
                       astrColumnNames, _
                       alngFieldTypes, _
                       astrFieldNames, 0, alngShapesLinked