PDA

View Full Version : Solved: Question about hyperlinks



jesmitch
03-16-2008, 01:28 PM
I am very green to VBA code and was looking for someone to point me in the right direction. I am needing to build a macro to go to a hyperlink, and part of the hyperlink needs to be pulled from a cell in Excel. For example, the website address would be test.com/*****/index.html where ***** would be pulled from a cell in Excel. I hope this makes sense and you can point me in the right direction.:dunno

Simon Lloyd
03-16-2008, 01:40 PM
This should work when added to a Sub:

ActiveSheet.Hyperlinks.Add Anchor:=Range("B1"), Address:= _
"www.test.com/ (http://www.test.com/)" & Range("A1").Value & "/index.html ", TextToDisplay:= _
"www.test.com/ (http://www.test.com/)" & Range("A1").Value & "/index.html"
Range("B1").Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
the only way i know was to build the hyperlink then follow it but the more experienced on here will probably come up with a better way!

jesmitch
03-16-2008, 01:43 PM
That helps tremendously. Thanks. Could this same prinicple be applied to another program other than excel that uses VBA? For example, if we have a back office program that can utilize VBA macros, could we use the same principles to call out part of the screen text to use in the hyperlink?

Simon Lloyd
03-16-2008, 01:47 PM
As i said i dont have that much knowledge, what i do know is if it uses VBA rather than VB then it should although depending on the application the wording/annotation can be different as they all have slight differences in the way you reference things!

jesmitch
03-18-2008, 01:15 PM
This is working good. I have an additional question though. I created a button on the excel spreadsheet with the code above and it works great. How could I make it so that when I click on the button, it does not put an anchor or anything in field B1?

mdmackillop
03-18-2008, 02:28 PM
ActiveWorkbook.FollowHyperlink "www.test.com/ (http://www.test.com/)" & Range("A1").Value & "/index.html"

lucas
03-18-2008, 02:43 PM
My shot, starter file was a kb entry by Joseph......searched the kb for hyperlink....

Option Explicit
Sub OpenWebsite()
Dim strWebsite As String
strWebsite = "http://www." & (Range("B1").Value) & ".com/"
'strWebsite = "http://www.vbaexpress.com/"
ActiveWorkbook.FollowHyperlink Address:=strWebsite, NewWindow:=True
End Sub

lucas
03-18-2008, 02:46 PM
ah, sorry Malcolm....I should have refreshed.....oh well. Better than no answer I guess.

jesmitch
03-19-2008, 05:44 AM
Thank you to everyone. It is greatly appreciated. I am a life long network technician who is just starting to dive into the world of VBA. Thanks for all of your help.

lucas
03-19-2008, 07:33 AM
jesmitch,
If you got a satisfactory answer then please mark your thread solved using the thread tools at the top of the page.

jesmitch
03-19-2008, 07:34 AM
My apologies, I forgot to do that. I will take care of this shortly.