ハイパーリンクの追加メソッド (Excel) | Microsoft Learn

指定した範囲または図形にハイパーリンクを追加するための構文は、expression.Addです。expressionはHyperlinksオブジェクトを示します。必要なパラメータは、Anchor(ハイパーリンクのアンカー)、Address(ハイパーリンクのアドレス)、およびオプションのSubAddress、ScreenTip、TextToDisplayです。テキストは文字列でなければなりません。例として、A5セルにMicrosoftのウェブサイトやメールリンクを追加する方法が示されています。サポートやフィードバックについては、Office VBAのサポートを参照してください。

指定された範囲またはシェイプにハイパーリンクを追加します。

構文

expression.Add (Anchor, Address, SubAddress, ScreenTip, TextToDisplay)

expression ハイパーリンクオブジェクトを表す変数。

パラメーター

名前 必須/オプショナル データ型 説明
Anchor 必須 オブジェクト ハイパーリンクのアンカー。Range または Shape オブジェクトのいずれか。
Address 必須 文字列 ハイパーリンクのアドレス。
SubAddress オプショナル バリアント ハイパーリンクのサブアドレス。
ScreenTip オプショナル バリアント マウスポインターがハイパーリンクの上にあるときに表示されるスクリーンティップ。
TextToDisplay オプショナル バリアント ハイパーリンクに表示されるテキスト。

戻り値

新しいハイパーリンクを表すHyperlinkオブジェクト。

TextToDisplay引数を指定する場合、テキストは文字列である必要があります。

この例ではセルA5にハイパーリンクを追加します。

With Worksheets(1) 
        .Hyperlinks.Add Anchor:=.Range("a5"), _ 
        Address:="https://example.microsoft.com", _ 
        ScreenTip:="Microsoft Web Site", _ 
        TextToDisplay:="Microsoft" 
    End With
    

この例ではセルA5にメールハイパーリンクを追加します。

With Worksheets(1) 
        .Hyperlinks.Add Anchor:=.Range("a5"), _ 
        Address:="mailto:someone@example.com?subject=hello", _ 
        ScreenTip:="Write us today", _ 
        TextToDisplay:="Support" 
    End With 
    

サポートとフィードバック

Office VBAやこのドキュメントに関して質問やフィードバックがありますか?サポートを受けたりフィードバックを提供する方法については、Office VBAサポートとフィードバックをご覧ください。

————-

Hyperlinks.Add method (Excel) | Microsoft Learn

Source link

Summary: Adding a Hyperlink in VBA

The Add method allows you to add a hyperlink to a specified range or shape in VBA.

Syntax

expression.Add(Anchor, Address, SubAddress, ScreenTip, TextToDisplay)
  • expression: A variable representing a Hyperlinks object.

Parameters

  • Anchor (Required, Object): The target for the hyperlink (a Range or Shape object).
  • Address (Required, String): The hyperlink’s main address (URL).
  • SubAddress (Optional, Variant): The subaddress within the hyperlink.
  • ScreenTip (Optional, Variant): Tooltip displayed when hovering over the hyperlink.
  • TextToDisplay (Optional, Variant): Text shown for the hyperlink (must be a string).

Return Value

Returns a Hyperlink object representing the newly created hyperlink.

Example Code

  1. Adding a hyperlink to a webpage:

    With Worksheets(1)
       .Hyperlinks.Add Anchor:=.Range("A5"), _
           Address:="https://example.microsoft.com", _
           ScreenTip:="Microsoft Web Site", _
           TextToDisplay:="Microsoft"
    End With
  2. Adding an email hyperlink:
    With Worksheets(1)
       .Hyperlinks.Add Anchor:=.Range("A5"), _
           Address:="mailto:someone@example.com?subject=hello", _
           ScreenTip:="Write us today", _
           TextToDisplay:="Support"
    End With

Support and Feedback

For support or feedback regarding Office VBA, refer to the official Office VBA support resources.

関連記事