Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Greg B
 
Posts: n/a
Default Hyperlink question

Hi all,

I have a worksheet with hyperlinks on it, I was wondering if it is possible
to have a userform with buttons on it when you press them to activate these
hyperlinks?

Something like this

on sheet link cell a2 I have a link called allergies

then on userform1 I want it to show the name allergies and show the
hyperlink.

I hope you can help

Thanks in advance

Greg


  #2   Report Post  
Jake Marx
 
Posts: n/a
Default

Hi Greg,

Here's one solution. Not sure if it's the easiest way, but it seems to
work. This will display a button on your UserForm for each hyperlink on a
worksheet named "link". The button's caption will be the same as the
hyperlink's text to be displayed, and when clicked, the button will launch
your browser and navigate to the URL specified in the hyperlink.


First, create a class module named "cBtnSink" and add the following code to
it:

Public WithEvents btn As MSForms.CommandButton

Public URL As String

Private Sub btn_Click()
ThisWorkbook.FollowHyperlink URL
End Sub


Next, add the following code to your UserForm:

Private mcolBtn As Collection

Private Sub UserForm_Activate()
Dim hyp As Hyperlink
Dim lHypNum As Long
Dim sCtlName As String
Dim objBtn As cBtnSink
Dim lY As Long

Set mcolBtn = New Collection
lY = 1

For Each hyp In Worksheets("link").Hyperlinks
lHypNum = lHypNum + 1
sCtlName = "btnHyp" & CStr(lHypNum)
With Controls.Add("Forms.CommandButton.1", _
sCtlName, True)
.Object.Caption = hyp.TextToDisplay
.Top = lY
lY = lY + .Height + 2
Height = lY + .Height
Width = .Width
End With
Set objBtn = New cBtnSink
objBtn.URL = hyp.Address
Set objBtn.btn = Controls(sCtlName)
mcolBtn.Add objBtn
Next hyp

Set objBtn = Nothing
End Sub

Private Sub UserForm_Terminate()
Dim l As Long

For l = 1 To mcolBtn.Count
mcolBtn.Remove 1
Next l

Set mcolBtn = Nothing
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Greg B wrote:
Hi all,

I have a worksheet with hyperlinks on it, I was wondering if it is
possible to have a userform with buttons on it when you press them to
activate these hyperlinks?

Something like this

on sheet link cell a2 I have a link called allergies

then on userform1 I want it to show the name allergies and show the
hyperlink.

I hope you can help

Thanks in advance

Greg


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Intra-workbook hyperlink: macro/function to return to hyperlink ce marika1981 Excel Discussion (Misc queries) 3 May 6th 05 05:47 AM
Hyperlink question Greg B Excel Discussion (Misc queries) 1 March 8th 05 04:42 PM
Removing hyperlink Frank Marousek Excel Discussion (Misc queries) 3 January 12th 05 09:53 PM
Hyperlink to specific sheet in Excel Web File jd17 Links and Linking in Excel 0 December 8th 04 09:03 PM
hyperlink question Arul Excel Worksheet Functions 2 December 3rd 04 11:46 PM


All times are GMT +1. The time now is 12:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"