+ Reply to Thread
Results 1 to 5 of 5

VBA loop through column and extract embedded hyperlink and create clickable hyperlink

  1. #1
    Registered User
    Join Date
    02-17-2014
    Location
    Florida
    MS-Off Ver
    Excel 2016
    Posts
    62

    VBA loop through column and extract embedded hyperlink and create clickable hyperlink

    Hello,

    I have data in a spreadsheet column 4 that is formatted like this:

    "DOC1#http://acmecorp.com/urlfiles/Doc1.pdf"

    This an export from MS Access table and the inclusion of the "#" allows the hyperlink to be clickable within the table (MS Accesses way of creating the "friendly name" and "location" in one line.

    Additionally, some of the rows have empty column cells and others have just static text without a hyperlink - i.e. "Document unavailable", or "N/A". These just need to be ignore.

    I'd like to loop through all rows to reformat the data in each cell so that it's now clickable via the Excel output file.

    So the Visible/Friendly name is "DOC1" and the location is the "Http://acmecorp.com/urlfiles/Doc1.pdf" And the "#" is just removed altogether.

    VBA needed:
    • For loop to check each row in sheet and check data in column 4 cell
    • See if there is a hyperlink in the cell "i.e. Find *http://" Then if it's there
    • Copy all text AFTER the "#" character
    • Store in string
    • Delete everything AFTER and INCLUDING the "#" to leave just the name of the doc
    • Use remaining text in cell (i.e. DOC1) as the Visible part of the hyperlink
    • Paste copied hyperlink from string as the "location" part of the hyperlink
    • If "http://" is not there, just ignore and move on to next row

    Can the HYPERLINK function be used? (HYPERLINK(link_location, [friendly_name]))

    Thank you in advance for your assistance.

  2. #2
    Registered User
    Join Date
    02-17-2014
    Location
    Florida
    MS-Off Ver
    Excel 2016
    Posts
    62

    Re: VBA loop through column and extract embedded hyperlink and create clickable hyperlink

    Update - I've tried the following, but get an error at the ".Hyperlink.Add" part. (Run-time error '483': Object doesn't support this property or method)

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-10-2021
    Location
    Paryzevo
    MS-Off Ver
    2k3
    Posts
    60

    Re: VBA loop through column and extract embedded hyperlink and create clickable hyperlink


    Maybe this way ?
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-17-2014
    Location
    Florida
    MS-Off Ver
    Excel 2016
    Posts
    62

    Re: VBA loop through column and extract embedded hyperlink and create clickable hyperlink

    Hi mjr veverka,

    I'm running this code from within MS Access since my Access code exports data to an Excel sheet and then manipulates the Excel sheet (i.e. formatting, coloring, etc.). But this all happens from within the MS Access database VBA.

    I modified your code slightly to update the column number as well as to account for Access not recognizing the "Application.Clean" command. But I get an error on the line with "If Right$(RTrim$(tbl(r, 1)), Len(crt2)) = crt2 Then" it highlights "tbl" with error "Compile Error ByVal Argument Type Mismatch".

    Here's the code:

    Error Happens at this line:
    Please Login or Register  to view this content.

    This allows the use of the "Clean" feature.
    Please Login or Register  to view this content.
    Modified code you provided:
    Please Login or Register  to view this content.
    The code runs flawlessly in Excel VBA, just not from the MS Access VBA side. I guess I could pass the code to Excel and execute this from within Excel, but I'll have to research that.

    Any thoughts?
    Last edited by Jay S.; 04-26-2021 at 12:46 PM.

  5. #5
    Registered User
    Join Date
    02-17-2014
    Location
    Florida
    MS-Off Ver
    Excel 2016
    Posts
    62

    Re: VBA loop through column and extract embedded hyperlink and create clickable hyperlink

    I was able to get the following code to work. In my case, I'm exporting data from MS Access to Excel and manipulating the data in Excel FROM MS Access VBA, so it posed a few issues with code recognition. This, however, worked.

    Please Login or Register  to view this content.
    Last edited by Jay S.; 04-26-2021 at 04:44 PM.

+ 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. userfom load value txtbox hyperlink to cell and create short hyperlink
    By remco77a in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2020, 08:38 AM
  2. Hyperlink to open embedded object for a column
    By carlrubber in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-13-2016, 11:38 PM
  3. Create Clickable Hyperlink in Word Document from excel Userform
    By craig62 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-10-2014, 08:27 AM
  4. [SOLVED] Excel 2010 Create a macro to check if cell contains hyperlink then apply hyperlink style
    By chasidar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-12-2013, 04:48 AM
  5. Excel 2007 : Clickable hyperlink that leads to a web page
    By imran9171 in forum Excel General
    Replies: 2
    Last Post: 02-29-2012, 09:14 PM
  6. Replies: 3
    Last Post: 01-13-2012, 12:11 PM
  7. Extract name and create a hyperlink
    By Ashish82 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-23-2008, 12:18 PM

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