Hi,
I am new here so I apologize in advance if I am not posting or explaining this properly. I have scoured the web and cannot find the answer so hopefully someone here can help...
I am using the =hyperlink function as follows...
Now the "Click Here" shows up fine and the link works when I click it manually...=HYPERLINK("http://"&A3&I19,"Click Here")
But I tried to get a macro to automatically click it....
And the code only works if it is an actual typed in hyperlink and not the hyperlink function using the formula...Sub test() For Each Cell In Selection ' Check that the cell contains a hyperlink If Cell.Hyperlinks.Count > 0 Then Cell.Hyperlinks(1).Follow (True) End If Next Cell End Sub
Hope I explained that right... any thoughts? Questions?
Thanks,
Henry
Hello Henry,
Welcome to the Forum!
As you have discovered, not all Hyperlinks are created equal. They both produce the same results, but internally they differ in how those results are accomplished. The Hyperlink protocol only describes the Hyperlink's behaviour, not how it has to accomplish it. So, Excel does it one way and VBA does it another way, and browsers do it still in another fashion, but the end results are the same. They just don't play well with others.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Thank you for the welcome...
So I guess my question is...
Is there a way to make them place nice together? I would like to use the macro to open multiple hyperlinks... the problem is the macro doesn't recognize excels formula syntax as an actual hyperlink?
Is that fair to say?
So can I run a script in the macro or change the hyperlink to a syntax that VBA recognizes?
Thanks,
Henry
You could iterate the formulae within the selection and test for HYPERLINK in that manner
(splitting the formula to extract the reference, building the hyperlink & following [then removing])
How viable that will be will largely depend on the consistency of the formulae themselves (eg embedded functions etc)
A very basic example assuming non-embedded function calls, valid (& basic) links etc...
(ie =HYPERLINK() rather than =IF(...,IF(...,HYPERLINK(...),""),"")
I've no doubt there's a better method...Sub Example() Dim rngF As Range, rngC As Range, strLink As String, hl As Hyperlink On Error Resume Next Set rngF = Selection.SpecialCells(xlCellTypeFormulas).Cells On Error GoTo 0 If Not rngF Is Nothing Then For Each rngC In rngF.Cells With rngC If InStr(1, .Formula, "HYPERLINK(", vbTextCompare) > 0 Then strLink = Split(.Formula, Chr(34))(1) With rngC .Hyperlinks.Add .Cells(1), strLink .Hyperlinks(1).Follow True .Hyperlinks(1).Delete .Formula = .Formula End With End If End With Next rngC End If Set rngF = Nothing End Sub
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Thank you for the response DonkeyOte, but I just figured it out...
Thank you to Leith Ross... your post helped me understand the issue and rethink my solution...
Here is what I did... not sure if this would be considered "clean code" but it works for me...
Basically Leith Ross helped me realize that I needed VBA to see it as a valid hyperlink.Dim hyperlinkstring As String For x = 1 To Selection.Rows.Count ActiveCell.Select hyperlinkstring = "http://" & ActiveCell.Value & Range("i19") ThisWorkbook.FollowHyperlink Address:=hyperlinkstring ActiveCell.Offset(1, 0).Select Next x
Thoughts?
Thanks,
Henry
If you need to Follow the hyperlink then genuine links is best approach.
FWIW, I noticed that the code I provided would not have worked for your samples (concatenation) and the strLink line would need to be revised
also as you have demonstrated there's no real need to add the links to the cells as I was doingstrLink = Evaluate(Split(Split(Left(.Formula, Len(.Formula) - 1), "=HYPERLINK(")(1), ",")(0))
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks