Actuarial Outpost
 
Go Back   Actuarial Outpost > Actuarial Discussion Forum > Software & Technology
FlashChat Actuarial Discussion Preliminary Exams CAS/SOA Exams Cyberchat Around the World Suggestions


Upload your resume securely at https://www.dwsimpson.com
to be contacted when new jobs meet your skills and objectives.


Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-04-2019, 04:31 PM
1695814's Avatar
1695814 1695814 is offline
Member
SOA AAA
 
Join Date: Aug 2002
Studying for nothing. I quit.
Favorite beer: Root
Posts: 36,505
Default create & open multiple hyperlinks in Excel via VBA

I'm trying to set up an Excel ss to list & then open a number of webpages.


Most of this information is probably unnecessary, but I'll provide it anyway.


In column A, I have a list (in text, not hyperlink) of the generic websites:
https://www.gocomics.com/ziggy/
https://www.gocomics.com/foxtrotclassics/
https://www.gocomics.com/calvinandhobbes/



Then, in column B, I convert them to today's comic (still in text, not hyperlink):
https://www.gocomics.com/ziggy/2019/7/4
https://www.gocomics.com/foxtrotclassics/2019/7/4
https://www.gocomics.com/calvinandhobbes/2019/7/4


Now, in column C, I convert them to hyperlinks:
=hyperlink(b1)
=hyperlink(b2)
=hyperlink(b3)


With the column C cells highlighted, I then run this macro that is supposed to open them, but it doesn't:
Code:
Sub BatchOpenHyperLinks_SelectedRanges()
    Dim objSelectedRange As Excel.Range
    Dim objHyperlink As Excel.Hyperlink

    'Get selected ranges
    Set objSelectedRange = Excel.Application.Selection
    For Each objHyperlink In objSelectedRange.Hyperlinks
        objHyperlink.Follow
    Next
End Sub
That macro works just fine on urls that I type in and hit enter but not ones created with the HYPERLINK fn.


Any ideas on how to make this work?
Reply With Quote
  #2  
Old 07-04-2019, 05:29 PM
CaptainCavy CaptainCavy is offline
Member
SOA AAA
 
Join Date: Sep 2001
Favorite beer: Winnie. Oh, that's my favorite Bear.
Posts: 150
Default

I think Excel treats the contents of the cells in column C as a formula, not a hyperlink (objHperlink returns nothing when I trace through it).

Try this:

Code:
Sub BatchOpenHyperLinks_SelectedRanges()
    Dim objSelectedRange As Excel.Range
    Dim objHyperlink As Excel.Hyperlink

    'Get selected ranges
    Set objSelectedRange = Excel.Application.Selection

    For Each cell In objSelectedRange
        ThisWorkbook.FollowHyperlink cell.Value
    Next
End Sub

Last edited by CaptainCavy; 07-04-2019 at 05:29 PM.. Reason: formatting
Reply With Quote
  #3  
Old 07-05-2019, 12:47 PM
1695814's Avatar
1695814 1695814 is offline
Member
SOA AAA
 
Join Date: Aug 2002
Studying for nothing. I quit.
Favorite beer: Root
Posts: 36,505
Default

Quote:
Originally Posted by CaptainCavy View Post
I think Excel treats the contents of the cells in column C as a formula, not a hyperlink (objHperlink returns nothing when I trace through it).

Try this:
Excellent. Thank you! It worked on my column B list...only those that were in the form of a URL.


Thanks for the help!


p.s. You have been immortalized in my Excel file because the macro is named "BatchOpenHyperLinks_SelectedRanges_CaptainCavy()" .

Last edited by 1695814; 07-05-2019 at 01:28 PM..
Reply With Quote
  #4  
Old 07-05-2019, 02:37 PM
CaptainCavy CaptainCavy is offline
Member
SOA AAA
 
Join Date: Sep 2001
Favorite beer: Winnie. Oh, that's my favorite Bear.
Posts: 150
Default

That's better than when someone named their pet salamander after me!
Reply With Quote
  #5  
Old 07-05-2019, 04:15 PM
ElDucky's Avatar
ElDucky ElDucky is offline
Free Mason
 
Join Date: Jul 2004
Location: In a van, down by the river
Studying for Let me worry about blank
Favorite beer: Trappistes Rochefort 8
Posts: 43,378
Default

Oh, I see! Then I guess everything's wrapped up in a neat little package.
__________________
I live near the cows.
Reply With Quote
  #6  
Old 07-06-2019, 07:24 PM
1695814's Avatar
1695814 1695814 is offline
Member
SOA AAA
 
Join Date: Aug 2002
Studying for nothing. I quit.
Favorite beer: Root
Posts: 36,505
Default

Quote:
Originally Posted by ElDucky View Post
Oh, I see! Then I guess everything's wrapped up in a neat little package.
RN?
Reply With Quote
Reply

Tags
vba

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT -4. The time now is 06:52 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
*PLEASE NOTE: Posts are not checked for accuracy, and do not
represent the views of the Actuarial Outpost or its sponsors.
Page generated in 0.27858 seconds with 11 queries