Partager via


WorkbookBase.SheetFollowHyperlink Event

Occurs when you click any hyperlink in a workbook.

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 Event SheetFollowHyperlink As WorkbookEvents_SheetFollowHyperlinkEventHandler
public event WorkbookEvents_SheetFollowHyperlinkEventHandler SheetFollowHyperlink

Examples

The following code example demonstrates a handler for the SheetFollowHyperlink event. The event handler keeps a list of all the hyperlinks in the current workbook that have been clicked, plus the names of the worksheets that contain these hyperlinks, in a ListBox control.

This example is for a document-level customization.

Private ListBox1 As ListBox

Private Sub WorkbookSheetFollowHyperlink()
    ListBox1 = Globals.Sheet1.Controls.AddListBox( _
        Globals.Sheet1.Range("B2", "C3"), "listBox1")
End Sub 


Sub ThisWorkbook_SheetFollowHyperlink(ByVal Sh As Object, _
    ByVal Target As Excel.Hyperlink) Handles Me.SheetFollowHyperlink

    Dim sheet As Excel.Worksheet = CType(Sh, Excel.Worksheet)
    ListBox1.Items.Add(sheet.Name & ":" & Target.Address)
End Sub
private ListBox listBox1;

private void WorkbookSheetFollowHyperlink()
{
    listBox1 = Globals.Sheet1.Controls.AddListBox(
        Globals.Sheet1.Range["B2", "C3"], "listBox1");

    this.SheetFollowHyperlink +=
        new Excel.WorkbookEvents_SheetFollowHyperlinkEventHandler(
        ThisWorkbook_SheetFollowHyperlink);
}

void ThisWorkbook_SheetFollowHyperlink(object Sh,
    Excel.Hyperlink Target)
{
    Excel.Worksheet sheet = (Excel.Worksheet)Sh;
    listBox1.Items.Add(sheet.Name + ":" + Target.Address);
}

.NET Framework Security

See Also

Reference

WorkbookBase Class

Microsoft.Office.Tools.Excel Namespace