Partager via


WorkbookBase.SetLinkOnData Method

Sets the name of a procedure that runs whenever a DDE link is updated.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Syntax

'Declaration
Public Sub SetLinkOnData ( _
    name As String, _
    procedure As Object _
)
public void SetLinkOnData(
    string name,
    Object procedure
)

Parameters

  • procedure
    Type: System.Object

    The name of the procedure to be run when the link is updated. This can be either a Microsoft Office Excel 4.0 macro or a Visual Basic procedure. Set this argument to an empty string ("") to indicate that no procedure should run when the link is updated.

Remarks

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Examples

The following code example gets the collection of all DDE links in the current workbook and then uses the SetLinkOnData method to run a macro named UPDATE_MACRO whenever one of the links is updated.

This example is for a document-level customization.

Private Sub WorkbookSetLinkOnData()
    Dim Links As Array = _
        CType(Me.LinkSources(Excel.XlLink.xlOLELinks),  _
        Array)
    If Links IsNot Nothing Then 
        Dim i As Integer 
        For i = 1 To Links.Length
            Me.SetLinkOnData(Links(i), "UPDATE_MACR0")
        Next i
    Else
        MsgBox("The workbook contains no DDE/OLE links.")
    End If 
End Sub
private void WorkbookSetLinkOnData()
{
    Array links = (Array)this.LinkSources(Excel.XlLink.xlOLELinks);

    if (links != null)
    {
        for (int i = 1; i <= links.Length; i++)
        {
            this.SetLinkOnData((string)links.GetValue(i), "UPDATE_MACR0");
        }
    }
    else
    {
        MessageBox.Show("The workbook contains no DDE/OLE links.");
    }
}

.NET Framework Security

See Also

Reference

WorkbookBase Class

Microsoft.Office.Tools.Excel Namespace