Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Feb 2002
    Location
    Sussex, England
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert Hyperlink in Excel Word (Word 2002/Excel 2002)

    This is quite complicated, so sorry if this sounds like garbage

    I am creating a Word template that users will fill in and then the data will be put into an Excel spreadsheet.

    Each file will be saved to a particular location with different names depending on data inputted.

    I would like to insert a hyperlink to the Word file that I have just saved into the Excel spreadsheet when the other data is put in there.

    I have used GetObject to define Excel and the data from the UserForms is inserting into Excel in the right places, but I can't find the right code to insert a hyperlink into a cell.

    Any suggestions very welcome. I am using the code which seems obvious to me (MyXL.ActiveSheet.Hyperlinks.Add Range("A1"), FilePath), but it's not working.

    Thanks for any efforts in advance, Chesney

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,892
    Thanks
    0
    Thanked 83 Times in 79 Posts

    Re: Insert Hyperlink in Excel Word (Word 2002/Excel 2002)

    Chesney,
    Your code is not referencing Range("A1") correctly - it belongs to myXL.Activesheet. Try something like:
    <pre>With myXL.Activesheet
    .Hyperlinks.add .Range("A1"), Filepath
    End with
    </pre>

    and see if that helps. If not, can you clarify whether you're getting an error, no hyperlink or a hyperlink that doesn't work?
    Regards,
    Rory
    Microsoft MVP - Excel.

  3. #3
    New Lounger
    Join Date
    Feb 2002
    Location
    Sussex, England
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert Hyperlink in Excel Word (Word 2002/Excel 2002)

    That didn't seem to help.

    I'm not getting an error, it just doesn't add a hyperlink.

    I'm actually trying to add a hyperlink to a cell in relation to a range, Range(RangeName).Cells(1,1)

    I have tried just using Range("A1") and I can't get that to work either.

    Thanks, Chesney

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,892
    Thanks
    0
    Thanked 83 Times in 79 Posts

    Re: Insert Hyperlink in Excel Word (Word 2002/Excel 2002)

    Chesney,
    I've just done a quick test and it worked fine for me using this (rough and ready) code:
    <pre>Sub TestHLink()
    Dim appExcel As Excel.Application
    Dim wbkNew As Excel.Workbook
    Dim strFilePath As String
    Set appExcel = New Excel.Application
    Set wbkNew = appExcel.Workbooks.Add
    strFilePath = ActiveDocument.FullName
    With wbkNew.ActiveSheet
    .Hyperlinks.Add .Range("A1"), strFilePath
    End With
    wbkNew.SaveAs "C:TestHLink.xls"
    wbkNew.Close
    Set wbkNew = Nothing
    appExcel.Quit
    Set appExcel = Nothing
    End Sub
    </pre>

    The only way I could get something similar to what you describe was if I didn't populate the strFilePath variable - in that case I got a blank hyperlink (i.e. you couldn't see it other than by the fact of the cursor changing over that cell).
    Can you post the exact code you're using? (in a text file if it's very long).
    Regards,
    Rory
    Microsoft MVP - Excel.

  5. #5
    New Lounger
    Join Date
    Feb 2002
    Location
    Sussex, England
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert Hyperlink in Excel Word (Word 2002/Excel 2002)

    Thank you so much, worked a treat!

    I think my actual problem was not having anything in my FilePath variable!

Posting Permissions

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