+ Reply to Thread
Results 1 to 6 of 6

VBA: How to add a hyperlink to a cell in a table in a Word doc

  1. #1
    Registered User
    Join Date
    10-18-2023
    Location
    Geel, Belgium
    MS-Off Ver
    Microsoft 365
    Posts
    3

    VBA: How to add a hyperlink to a cell in a table in a Word doc

    Hi all,

    I am new here and new to VBA coding. I am using and modifying an Excel VBA subroutine that generates a Word document with tables populated with information. Now I'm looking to add a snipet of code that lets me turn text in selected cells into hyperlinks.

    This is what imo relevant parts of the current code look like:

    Please Login or Register  to view this content.
    Now I'd like to encode that e.g. hyperlink X is added to TEXT A in Cell (2,2).

    Does someone know which code to use?
    Last edited by alansidman; 10-18-2023 at 03:51 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,743

    Re: VBA: How to add a hyperlink to a cell in a table in a Word doc

    Code Tags Added
    Your post does not comply with our General Guide lines. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html

    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)

    However, if you continue to not use code tags, you can expect to have your thread BLOCKED until you add them yourself.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,539

    Re: VBA: How to add a hyperlink to a cell in a table in a Word doc

    I don't know if I understood you correctly. The following code will insert the hyperlink after TEXT A.
    Please Login or Register  to view this content.
    And if you want to insert a hyperlink into Cell(2,2) and display TEXT A in that cell, then like this:
    Please Login or Register  to view this content.
    Artik

  4. #4
    Registered User
    Join Date
    10-18-2023
    Location
    Geel, Belgium
    MS-Off Ver
    Microsoft 365
    Posts
    3

    Re: VBA: How to add a hyperlink to a cell in a table in a Word doc

    Hi Artik, I tried the 2nd one and it worked. Fantastic! Thank you so so much! OZ77
    Last edited by OZ77; 10-19-2023 at 09:17 AM.

  5. #5
    Registered User
    Join Date
    10-18-2023
    Location
    Geel, Belgium
    MS-Off Ver
    Microsoft 365
    Posts
    3

    Re: VBA: How to add a hyperlink to a cell in a table in a Word doc

    One follow-up question though (not a new request): I also want to add the same hyperlink to a bunch of different cells, either adjacent cells or cells dispersed over the table. Is there a smart way to do that? As opposed to the stupid way of having to encode one-by-one the same hyperlink to a bunch of individual cells.

  6. #6
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,539

    Re: VBA: How to add a hyperlink to a cell in a table in a Word doc

    If you want to insert a hyperlink to all cells of a specific column (in the example, to the second column), you create a loop that will "run" through the rows of the table, and then point to the second cell in each row:
    Please Login or Register  to view this content.
    In case the cells are scattered around the table, create an array to store the cell addresses. Each address consists of a row and column number separated by a comma and must be separated by a space:
    Please Login or Register  to view this content.
    The Split function will create elements containing the address of each listed cell. The second Split function will return the row number and column number of each cell.
    Please Login or Register  to view this content.
    Artik

+ 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] Hyperlink to word instead of cell
    By CharlieK in forum Excel General
    Replies: 5
    Last Post: 12-07-2016, 03:43 PM
  2. In Excel, Word Document hyperlink Table Cell partial text to bookmark.
    By Kalithro in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-25-2016, 11:16 PM
  3. Hyperlink excel cell to word
    By Luther.King in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-28-2015, 06:44 AM
  4. Replies: 0
    Last Post: 03-01-2013, 09:34 AM
  5. Replies: 1
    Last Post: 04-03-2012, 03:01 PM
  6. Hyperlink ONE word in a cell ???
    By mountainsun in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-07-2005, 11:06 PM
  7. [SOLVED] Hyperlink a word within a cell
    By kchambers in forum Excel General
    Replies: 2
    Last Post: 03-09-2005, 01:06 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