• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2714
  • Last Modified:

hyperlink in vba msgbox

I have a message box that appears when a button is clicked, in the message box is a contact email address and hyperlink to a url.  How can make these appear as real links (blue underlined) so that a user can just click on them?
0
kevin1973
Asked:
kevin1973
  • 2
1 Solution
 
WATYFCommented:
As far as I'm aware, there is no way to add an active hyperlink to a MsgBox. (this could be entirely incorrect, though)

But you can instead create a UserForm that looks the exact same as the message box then do this:

For each link (i.e. email, http) create a Label (i.e. Label1). Select the properties for the Label and set the font to blue/underlined. Then, in the Form's module, input this code.

****************************************************

Private Sub Label1_Click()

    Link = "http://www.expert-exchange.com"

    On Error GoTo Label1_Err
    ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True
    Unload Me
    Exit Sub

Label1_Err:
    MsgBox "Cannot open " & Link

End Sub

********************************************


For email links you would use:

Link = "mailto:watyf@expert-exchange.com"


Basically you're making a custom "message box", and every time you need to display a link (for email or what have you) you just use a separate label for that text.


WATYF
0
 
FTACommented:
You're trying to get blood out of a stone my man.

It's a messagebox object : it returns ok,yes,no or cancel. Thats it - it can do no more than that.

Where are the hyperlinks coming from?
Are they on a sheet?
0
 
WATYFCommented:
sorry... I gave you some bad code in there... use this for the macro portion.


*********************************

Private Sub Label1_Click()

    On Error GoTo Label1_Err
   
    HyprLnk = "http://www.experts-exchange.com"
    ActiveWorkbook.FollowHyperlink Address:=HyprLnk, NewWindow:=True
    Exit Sub

Label1_Err:
   MsgBox "Cannot open " & HyprLnk

End Sub

*********************************



WATYF
0
 
kevin1973Author Commented:
I never thought about creating a form for a custom message box.  Thanks for the idea, it worked perfectly.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now