Macro - Remove Links to External Data

Started by h3lp_pl3as3, December 10, 2019, 04:07:30 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

h3lp_pl3as3

Hi everyone,

First post here!

I'm creating detailed diagrams using Visio Pro for Office 365 (32-bit) linked to an access DB with a number of tables. The data in the DB drives some of the shape formatting, with various icons and colouring on the diagram.

The diagrams themselves are quite detailed in nature and it looks like some of the linkages have gone haywire. Each data table refers to one shape time only - square boxes for systems, lines for data transfers and a rounded edge rectangle for functions. In terms of linkages, one shape should only be linked to one row of one table.

The issue that I have is that some shapes are linked to multiple rows of various tables, what I am looking for, is some code to: remove all data apart from a particular field so that I can automate the process to relink the right shape to the right source. Ultimately what I am looking for is an automated way of unlinking shapes from data sources, and for the data to be permanently removed

In terms of removing the data, I have tried the macros outlined in these links:
- http://visguy.com/vgforum/index.php?topic=8006.0
- http://visguy.com/vgforum/index.php?topic=6106.0
- http://visguy.com/vgforum/index.php?topic=5602.0

Hopefully someone can help.....please!




Thomas Winkel

#2
Hi,

we use the code below in our project:

  • Unlink shape from DRS
  • Set values of all linked attributes to ""
  • Delete all generated attributes (beginning with "_VisDM_")


Public Sub CleanAndUnlinkShapeData(shp As Visio.Shape)
    Dim DrsIDs() As Long
    Dim Indices() As Long
    Dim i As Integer
    Dim n As Integer
   
    shp.GetLinkedDataRecordsetIDs DrsIDs
    For n = LBound(DrsIDs) To UBound(DrsIDs)
        shp.GetCustomPropertiesLinkedToData DrsIDs(n), Indices
        shp.BreakLinkToData DrsIDs(n)
        For i = UBound(Indices) To LBound(Indices) Step -1
            If Left(shp.Section(visSectionProp).row(Indices(i)).NameU, 7) = "_VisDM_" Then
                shp.DeleteRow visSectionProp, Indices(i)
            Else
                shp.CellsSRC(visSectionProp, Indices(i), visCustPropsValue).FormulaU = Chr(34) & Chr(34)
            End If
        Next i
    Next n
End Sub