Export (0) Print
Expand All
Expand Minimize

Shape.LinkToData Method (Visio)

Links a shape to a data row in a data recordset.

NoteNote

This Visio object or member is available only to licensed users of Microsoft Visio Professional 2010 or Visio Premium 2010.

Version Added: Visio 2007

expression .LinkToData(DataRecordsetID, RowID, AutoApplyDataGraphics)

expression An expression that returns a Shape object.

Parameters

Name

Required/Optional

Data Type

Description

DataRecordsetID

Required

Long

The ID of the data recordset containing the data to link to.

RowID

Required

Long

The ID of the row in the data recordset containing the particular data record to link to.

AutoApplyDataGraphics

Optional

Boolean

Whether to automatically apply a data graphic to the linked shapes. See Remarks for more information.

Return Value

Nothing

The Shape.LinkToData method functions much like the same method of the Selection object, Selection.LinkToData, except that it links a single shape, instead of a selection of shapes, to a single data row.

If you pass True for the AutoApplyDataGraphics parameter, Microsoft Visio re-applies the existing data graphic to a shape if it already had a data graphic applied before you called the method. For a shape that previously had no data graphic, Visio applies the data graphic most recently applied to any other shape in the current document.

The following Microsoft Visual Basic for Applications (VBA) macro shows how to use the LinkToData method to link a shape to a data row.

Before running this macro, add at least one data recordset to the DataRecordsets collection of the document. The macro uses the ID of the data recordset most recently added to the collection. It draws a rectangle shape on the page and links it to the data in the first row of the data recordset, while applying the default data graphic to the shape.

Public Sub LinkToData_Example() 
 
    Dim vsoDataRecordset As Visio.DataRecordset 
    Dim vsoShape As Visio.Shape 
    Dim intCount As Integer 
     
    intCount = Visio.ActiveDocument.DataRecordsets.Count 
    Set vsoDataRecordset = Visio.ActiveDocument.DataRecordsets(intCount) 
     
    Set vsoShape = ActivePage.DrawRectangle(2, 2, 5, 5) 
     
    vsoShape.LinkToData vsoDataRecordset.ID, 1, True 
 
End Sub
Show:
© 2014 Microsoft