Add a Hyperlink to a VBA MsgBox in Excel

VBA & macros · Updated November 18, 2026

You cannot add a genuinely clickable hyperlink inside Excel VBA’s built-in MsgBox: it displays plain text and its standard buttons return choices such as Yes or No. You can show a URL and ask whether to open it, then use VBA to launch it; for a dialog with a link-like control, build a small UserForm instead.

Why a MsgBox link is not clickable

The VBA MsgBox function creates a standard system dialog. Its message area accepts text, including a web address, but it does not interpret that text as a hyperlink. Typing or pasting https://www.example.com/ into the message does not turn it into a link the reader can click.

The buttons are also limited to predefined choices such as OK, Cancel, Yes, and No. VBA can check which button the person selected, but the buttons cannot be relabeled as a custom web address or given hyperlink behavior. This is a limitation of the built-in dialog, not a missing formatting option in Excel.

That distinction suggests two practical approaches: keep the simple MsgBox and open the URL after a deliberate Yes response, or create a custom form when the user needs a control that looks and behaves like a link.

Open a URL after a Yes response

For a short prompt, this pattern is usually the closest match to “add a hyperlink to a MsgBox.” The message displays the destination, and choosing Yes asks Excel to follow it. Choosing No simply ends the procedure.

Public Sub AskToOpenWebsite()
    Dim targetUrl As String
    Dim answer As VbMsgBoxResult

    ' Set the destination to a known, trusted address.
    targetUrl = "https://www.example.com/"

    ' Show the address and ask before opening it.
    answer = MsgBox("Open this webpage?" & vbCrLf & targetUrl, _
                    vbQuestion + vbYesNo, "Open website")

    If answer = vbYes Then
        ThisWorkbook.FollowHyperlink Address:=targetUrl
    End If
End Sub

Put this procedure in a standard VBA module. In Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic Editor, choose Insert > Module, and paste the procedure there. Run AskToOpenWebsite from the editor or assign it to a worksheet button. If you use a button, the user can launch the prompt without opening the Macros dialog.

ThisWorkbook.FollowHyperlink asks Excel to follow the supplied address; the link normally opens in the computer’s default browser. The browser, organization policy, or Office security settings may affect the result. The MsgBox itself still does not contain a clickable link: selecting Yes triggers a separate VBA action.

What the code does and how to adapt it

targetUrl stores the address in one place, so the same value appears in the prompt and is passed to Excel. answer stores the result of the dialog as a VbMsgBoxResult. The If statement opens the link only when the result is vbYes; clicking No or closing the dialog does not open it.

Change the URL and the prompt text to suit your workbook. If the destination is stored in a cell, you can read it into targetUrl rather than hard-coding it. For example, with the address in cell A1 on the active worksheet, replace the assignment with targetUrl = ActiveSheet.Range("A1").Value. Check that the cell contains a complete, intended address before following it. A blank or malformed value may fail or lead somewhere unexpected.

You can also change the message-box style, but the choices remain standard. For instance, vbQuestion + vbYesNo displays a question icon with Yes and No buttons. The icon does not affect how the URL works. Avoid wording that implies the address itself is clickable; say “Choose Yes to open” so the user understands the interaction.

When to use a UserForm instead

If the requirement is a visible, clickable-looking link inside a dialog, a VBA UserForm gives you more control. Add a UserForm in the Visual Basic Editor with Insert > UserForm, then use the Toolbox to add a Label and a CommandButton. A Label does not automatically become a web hyperlink, but its click event can run VBA. A button is often clearer and more accessible because its purpose can be stated explicitly.

For example, set the form’s name to frmLink, add a CommandButton named cmdOpenLink with the caption Open webpage, and add another named cmdClose with the caption Close. Put the following event procedures in the form’s code window:

Private Sub cmdOpenLink_Click()
    Dim targetUrl As String

    ' Use a known destination for this example.
    targetUrl = "https://www.example.com/"
    ThisWorkbook.FollowHyperlink Address:=targetUrl
End Sub

Private Sub cmdClose_Click()
    ' Close the form without opening the link.
    Unload Me
End Sub

To display that form, add this separate procedure to a standard module:

Public Sub ShowLinkDialog()
    ' Display the custom dialog.
    frmLink.Show
End Sub

In a finished form, include the full URL in a label so the person can see the destination before choosing the button. You can style a Label with blue, underlined text and write a lblLink_Click event that follows the address, but that appearance alone does not provide all the behavior or accessibility cues of a true web link. A plainly labeled button is less likely to be mistaken for a built-in hyperlink.

Choosing between the two approaches

  • Use a MsgBox confirmation when the task is simply to ask permission before opening one known URL. It needs little interface setup and uses familiar Yes and No choices.
  • Use a UserForm when the dialog needs a clearly labeled Open button, several controls, explanatory text, or a more tailored layout.
  • Use a worksheet hyperlink when the destination should remain visible and available without running a macro. A cell hyperlink is often preferable for a permanent reference.
  • Use a normal MsgBox with a displayed address when users only need to read or copy the URL and you do not want the workbook to open a browser automatically.

For a one-time notice, a custom form can be unnecessary overhead. Conversely, a message box is not a good substitute for a form if users need multiple actions or must review details before continuing. Choose the simplest interface that makes the next action and destination clear.

Safety, workbook format, and platform limits

Only follow URLs that are expected and trustworthy. If a link comes from a worksheet cell, imported file, or user input, treat it as untrusted data: validate the value and make the destination visible before opening it. Do not silently open a changing or externally supplied URL just because a macro runs. A confirmation is useful, but it does not prove that a destination is safe.

Save a workbook containing VBA as an Excel Macro-Enabled Workbook (.xlsm) if you need to retain its macros. Excel may display a security warning when the file opens; enable macros only when the workbook and its source are trusted. VBA macros do not run in Excel for the web, so this approach requires the desktop application. Excel for Mac supports VBA, but editor shortcuts and some form behavior can differ; the browser handoff depends on the Mac’s environment. Test the finished workbook on the platform where it will be used.

Before running a macro that changes workbook content, save a copy of the file. Macro actions cannot be undone with Ctrl+Z, even though the example above only opens a web address. That habit is useful whenever you add or modify VBA.

Common problems and how to diagnose them

  • The URL appears but is not clickable: that is expected in a MsgBox. Use the Yes-response pattern or a UserForm event instead.
  • Clicking Yes does nothing or raises an error: check that the URL is complete, that the macro is allowed to run, and that the workbook is using the intended address. Try a known public example address to separate code issues from destination issues.
  • The link opens in an unexpected place: Excel delegates the destination to the system and installed applications. Check the default browser and any organization-managed security settings.
  • The macro disappears after saving: save as .xlsm, not as a macro-free .xlsx file.
  • The code cannot find the form: confirm the UserForm’s actual name in its Properties window and make the name in frmLink.Show match it.

When debugging, run the procedure from the Visual Basic Editor and inspect the exact value of targetUrl. If the address is read from a cell, verify the worksheet and cell reference too; a valid link in the wrong cell can be just as confusing as a broken URL.

Frequently Asked Questions

Can I make part of a VBA MsgBox message clickable?
No. The built-in MsgBox displays plain text and does not support rich-text hyperlinks. Use a UserForm control with a click event, or open the URL after the user selects Yes.

Can I change a MsgBox button to say “Open link”?
No. The standard MsgBox button captions are fixed. A UserForm lets you add a CommandButton with a custom caption such as “Open webpage.”

Can a MsgBox open a website automatically?
Yes. VBA can call FollowHyperlink without waiting for a button choice, but opening a URL unexpectedly can surprise users. For most workbook prompts, showing the destination and asking first is clearer.

Will this macro work in Excel for the web?
No. Excel for the web does not run VBA macros. Use the desktop Excel application for this code, or provide a regular worksheet hyperlink that users can click in supported Excel versions.

Does the UserForm Label create a real hyperlink by itself?
No. A Label is a form control, not a web-link object. Its click event can call FollowHyperlink, but the VBA event is what makes the action happen.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.