WorkbookBase.LinkInfo(String, XlLinkInfo, Object, Object) 方法

定義

取得連結日期和更新狀態。

public object LinkInfo (string name, Microsoft.Office.Interop.Excel.XlLinkInfo linkInfoArgument, object type, object editionRef);
member this.LinkInfo : string * Microsoft.Office.Interop.Excel.XlLinkInfo * obj * obj -> obj
Public Function LinkInfo (name As String, linkInfoArgument As XlLinkInfo, Optional type As Object, Optional editionRef As Object) As Object

參數

name
String

連結名稱。

linkInfoArgument
XlLinkInfo

其中一個 XlLinkInfo 值,指定傳回資訊的類型。

type
Object

其中一個 XlLinkInfoType 值,指定傳回資訊的連結類型。

editionRef
Object

如果連結含有版本資訊,此參數將版本參照指定為 R1C1 樣式的字串。 EditionRef 如果活頁簿中有多個具有相同名稱的發行者或訂閱者,則需要 。

傳回

表示連結相關資訊的值。 當 LinkInfoArgumentxlUpdateState 時,如果連結會自動更新則此方法傳回 1,如果連結必須手動更新則傳回 2。

範例

下列程式代碼範例會使用 取得目前活頁簿中的 DDE/OLE 連結集合,然後使用 LinkInfo 方法來判斷每個 DDE/OLE 連結會自動或手動更新。

此範例適用於檔層級自定義。

private void WorkbookLinkInfo()
{
    // Get the collection of DDE/OLE links in the workbook.
    Array links = (Array)this.LinkSources(Excel.XlLink.xlOLELinks);

    // If there are DDE/OLE links, then display how each link
    // updates.
    if (links != null)
    {
        for (int i = 1; i <= links.Length; i++)
        {
            string linkName = (string)links.GetValue(i);
            int updateValue = (int)this.LinkInfo(linkName,
                Excel.XlLinkInfo.xlUpdateState,
                Excel.XlLinkInfoType.xlLinkInfoOLELinks);

            if (updateValue == 1)
            {
                MessageBox.Show(linkName + " link updates automatically.");
            }
            else if (updateValue == 2)
            {
                MessageBox.Show(linkName + " link updates manually.");
            }
        }
    }
    else
    {
        MessageBox.Show("The workbook contains no DDE/OLE links.");
    }
}
Private Sub WorkbookLinkInfo()
    ' Get the collection of DDE/OLE links in the workbook.
    Dim Links As Array = _
        CType(Me.LinkSources(Excel.XlLink.xlOLELinks),  _
        Array)

    ' If there are DDE/OLE links, then display how each link
    ' updates.
    If Links IsNot Nothing Then
        Dim i As Integer
        For i = 1 To Links.Length
            Dim UpdateValue As Integer = Me.LinkInfo(Links(i), _
                Excel.XlLinkInfo.xlUpdateState, _
                Excel.XlLinkInfoType.xlLinkInfoOLELinks)

            If UpdateValue = 1 Then
                MsgBox(Links(i) & " link updates automatically.")
            ElseIf UpdateValue = 2 Then
                MsgBox(Links(i) & " link updates manually.")
            End If
        Next i
    Else
        MsgBox("The workbook contains no DDE/OLE links.")
    End If
End Sub

備註

選擇性參數

如需選擇性參數的資訊,請參閱 Office 方案中的選擇性參數

適用於