Macro for to activate Hyperlink

Xr8y

New Member
Joined
Jan 22, 2011
Messages
28
I've created a simple macro to open a hyperlink... but if there is no hyperlink in the cell, I want an error message to pop up saying "Please select a hyperlink"

Any help appreciated! :)


Sub OpenHyperlink()
'
' OpenHyperlink Macro
'
' Keyboard Shortcut: Ctrl+q
'
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
End Sub
 
Try something like this:

Code:
Sub OpenHyperlink()
' Keyboard Shortcut: Ctrl+q
'
Dim cCell as Range
Set cCell = Selection.Cells(1,1)

If cCell.Hyperlinks.Count > 0 Then
    cCell.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Else
    MsgBox "Please select a hyperlink"
End If
End Sub
Does that help?
 
Upvote 0
Code:
Sub OpenHyperlink()
    '
    ' OpenHyperlink Macro
    '
    ' Keyboard Shortcut: Ctrl+q
    '
    If ActiveCell.Hyperlinks.Count Then
        ActiveCell.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
    Else
        MsgBox "Please select a hyperlink.", vbCritical, "Not a Hyperlink"
    End If
End Sub
 
Upvote 0
Code:
[/FONT]
[FONT=Courier New]Sub try()[/FONT]
[FONT=Courier New]If ActiveCell.Hyperlinks.Count = 0 Then
     MsgBox "Please select hyperlink"
    Else
    Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
    End If
End Sub
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top