+ Reply to Thread
Results 1 to 7 of 7

VBA Macro to open all hyperlinks in selected cells

  1. #1
    Registered User
    Join Date
    03-13-2020
    Location
    Italy
    MS-Off Ver
    365
    Posts
    3

    VBA Macro to open all hyperlinks in selected cells

    Hi everyone,

    I'm new to the forum and I'm seeking for help with a little VBA macro.
    My goal is to open all links in the selected cells. They're URLs pointing to different part of my websites.

    Warning: I'm learning to code in VBA so this is a newbie request for help.

    This is the code:

    Please Login or Register  to view this content.
    It correctly opens the first link in the selected cells but then it stops with an error in this line of code "ActiveWorkbook.FollowHyperlink a.Value".
    What's wrong and why?

    Thanks for your help!
    Last edited by Blablolat; 03-13-2020 at 11:09 AM. Reason: Better Title

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA Macro to open all hyperlinks in selected cells

    Welcome to the Forum Blablolat !

    What is the error code and message? What is the value of "a" when this error occurs? Are you sure that it is a valid URL?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    03-13-2020
    Location
    Italy
    MS-Off Ver
    365
    Posts
    3

    Re: VBA Macro to open all hyperlinks in selected cells

    Thank you for your answer 6StringJazzer,

    1) Pop up error:
    Run-time error '5': Invalid procedure call or argument

    When I click "debug" the line of code "ActiveWorkbook.FollowHyperlink a.Value" is highlighted.

    2)the value of "a" is the URL in the first cell selected, the one that is correctly opened in the browser.

    3)The URLs may be part of the problem. Let me explain:

    - with plain simple URLs copied from the browser or typed in manually (I'm not allowed to post links but I tried with google, amazon etc) the following code works perfectly:
    Please Login or Register  to view this content.
    - The URLs I need to work with are created with a CONCAT from different cells and then turned into hyperlink with HYPERLINK() function.
    These link are not working with the above code. After extensive researches on google I stumbled in the code in my original post (ActiveWorkbook.FollowHyperlink a.Value)and that worked with my URLs.
    I don't understand the difference and couldn't find it anywhere. So I'm stuck here. There are two possible solutions:

    a) EASIER (maybe): properly turn into links the URLs obtained from a CONCAT function and use the working VBA code
    b) HARDER (for me anyway): fix the code that works with my URLs obtained from a CONCAT function

    Any kind of help is much appreciated.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA Macro to open all hyperlinks in selected cells

    When you type a URL into a cell, Excel by default will automatically turn it into a clickable hyperlink. That is almost certainly the case with "plain simple URLs copied from the browser or typed in manually." In this case, the cell has an attribute called Hyperlink that has the URL as the Address attribute. You can see this if you right-click on the cell, then select "Link" from the menu. My point here is that the text in the cell is a separate attribute from the underlying Hyperlink attribute. In fact, they do not have to be the same string. The second bit of code you posted refers to the underlying Hyperlink attribute. That is why it works for typed-in URLs.

    When you use the HYPERLINK function to create a link, there is no underlying Hyperlink attribute. It is all done through the formula. If you right-click on the cell, the "Link" option is grayed out. So you can't use Hyperlink.Follow.

    None of this explains the error you are getting described in your first post. Are you using the second argument in HYPERLINK to display a "friendly" name for the URL, or do you see the actual URL in the cell? If you are displaying a friendly name, that will be the Value of the cell, and cannot be followed as a link. If not, then I cannot explain why you are getting the error. However, I would advise attaching your file if there is no private data. See yellow banner at the top of the page.

  5. #5
    Registered User
    Join Date
    03-13-2020
    Location
    Italy
    MS-Off Ver
    365
    Posts
    3

    Re: VBA Macro to open all hyperlinks in selected cells

    Well, I have good news.

    I couldn't share the file with my URLs since they contained sensitive informations so I made a new file with random addresses and the very same vba code. It worked flawlessy without any error. So I tried to recreate from scratch the sheet with my URLs and the same vba code and it worked too! Took me a while to do hence my delay in replying to you.

    For whatever reason the file I was working initially (maybe) got corrupted.

    Anyway, thanks a lot for your explanation about hyperlinks creation.
    Have a nice day

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA Macro to open all hyperlinks in selected cells

    If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

    If a member helped you solve your problem, consider adding to their reputation by clicking on the star icon addreputationiconsmall.jpg below their name.t was solved.

  7. #7
    Registered User
    Join Date
    02-09-2020
    Location
    Kamloop, BC Canada
    MS-Off Ver
    Windows 10
    Posts
    1

    Re: VBA Macro to open all hyperlinks in selected cells

    I tried to use the 6 lines of code above but it would not open my link ../test.kmz to Google Earth. I typed in the link. Wonder why it doesn't work. I figure if I get one to work multiple links will work as well. Any thoughts?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Follow Selected Hyperlinks - VIsible Cells only.
    By NewYears1978 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2019, 11:15 AM
  2. Open Hyperlinks within a selected range
    By karlwarnkester in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-18-2019, 03:54 PM
  3. Macro: Print hyperlinks in sheets, selected by checkbox.
    By MalcolmXcel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-20-2017, 11:54 AM
  4. Macro to open range of hyperlinks
    By mattmc419 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-18-2013, 10:19 AM
  5. [SOLVED] Macro to separate and open hyperlinks
    By penfold1992 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-04-2013, 06:27 AM
  6. macro to open hyperlinks
    By abuchan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-02-2010, 12:32 AM
  7. Looping Macro to open list of hyperlinks
    By barksmith in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-28-2009, 10:13 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1