Consulting

Results 1 to 4 of 4

Thread: VBA: How to add a hyperlink to a cell in a table in a Word doc generated from Excel

  1. #1
    VBAX Newbie
    Joined
    Oct 2023
    Posts
    2
    Location

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

    Hi all,


    I am new here and new to VBA coding. I am using and modifying an Excel VBA subroutine that generates, from an Excel file, 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:


    (...)
        Dim wrdApp As Word.Application
        Dim wrdDoc As Word.Document
    (...)
        Set wrdApp = CreateObject("Word.Application")
        Set wrdDoc = wrdApp.Documents.Add
        wrdDoc.PageSetup.Orientation = wdOrientLandscape
    (...)
        Set objTable = wrdDoc.Tables(wrdDoc.Tables.Count)
        objTable.Style = "Table Grid"
    (...)
        With objTable
            .Cell(2, 2).Range.Text = Chr(10) & "TEXT A"
                .Cell(2, 2).Range.Font.Bold = True
            .Cell(4, 2).Range.Text = "TEXT B"
                .Cell(4, 2).Range.Font.Bold = True
    (...)

    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?

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Welcome to VBAX OZ77. Have a read here. https://groups.google.com/g/microsof.../c/3tU7eLfJKTo
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Newbie
    Joined
    Oct 2023
    Posts
    2
    Location
    Thanks so much, Aussiebear. That was very useful!

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    If you are happy with the result can you mark this thread as Solved please? Go to Thread tools and select Mark thread as Solved.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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