共用方式為


WorkbookBase.SetLinkOnData(String, Object) Method

Definition

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

public void SetLinkOnData (string name, object procedure);
member this.SetLinkOnData : string * obj -> unit
Public Sub SetLinkOnData (name As String, Optional procedure As Object)

Parameters

name
String

The name of the DDE/OLE link, as returned from the LinkSources(Object) method.

procedure
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.

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 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.");
    }
}
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

Remarks

Optional Parameters

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

Applies to