PDA

View Full Version : Activating Hyperlinks



colh99
08-19-2010, 01:54 AM
Hello everyone

I have a workbook with 2 sheets "input" and "links". The "links" sheet is a table of material codes, descriptions, suppliers, and a hyperlink to specification sheets for each material/supplier.

The user will enter a material code in A1 of the "input" sheet, vlookups will fill Cells B2:E21 with details of all the entries that match the code, i.e column B (code), Column C (material description) ,Column D (supplier), and column E (the row number of the links sheet that contains the hyperlink).

I would like a code so the once the user has entered a material code which, for example, returns 4 entries and selects the entire row containing the entry of interest and the marco will active the correct hyperlink in column G row ??? of the "links" sheet.

Being new to vba I cant record the macro because of the variable. I have looked on this and other sites for a clue of how to do it and I am either looking in the wrong places or not understanding what I see because what ever I have tried doesn't work.

Thanks in advance

austenr
08-19-2010, 11:56 AM
What have you tried? Also can you post a sample workbook. Welcome aboard, enjoy the ride!!!

colh99
08-19-2010, 03:30 PM
Hi austenr

Thanks for your response.

I have attached a sample file to look at.

You will see that in A1 of the input sheet is 100001 and that displays 19 lines of white pepper from 19 suppliers. If the user wants to see the specification sheet from supplier M, I want them to select the row by clicking on the row number and this would active the hyperlink that is in E16 of the links sheet. (Spec is the friendly name for all the hyperlinks)


I have tried recording the task but I have to manualy select the correct link. As I don't know much about VBA I dont know how to tell it the correct row of the links sheet. When the sheet is complete there will be 1100-1200 entries in total each with its own hyperlink.

Thanks

colh99

colh99
08-24-2010, 09:03 AM
I have this code that does what I want

Sub runlink()
'
'runlink
'
'Dim requiredrow As String

Application.ScreenUpdating = False
requiredrow = ActiveCell.Formula
Sheets("LINKS").Visible = True
Sheets("LINKS").Select
Range("E" & requiredrow).Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Sheets("LINKS").Visible = False
Application.ScreenUpdating = True

End Sub

I have 3 questions
1. How do I post Code properly?

2. Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
what does AddHistory do?

3. how can I avoid a runtime error when the link doesn't work for example when the linked file has been removed but the hyperlink cell entry has not?

Thanks