+ Reply to Thread
Results 1 to 13 of 13

macro to create a hyperlink from excel to word document.

  1. #1
    Registered User
    Join Date
    01-25-2013
    Location
    seville
    MS-Off Ver
    Excel 2007
    Posts
    16

    macro to create a hyperlink from excel to word document.

    Hi there.

    I'm programming a macro which have to open a word document and (besides other stuff) create a hyperlinks in the opened word document. I've tried the next code

    PHP Code: 
    Sub escribe()
        
    Dim objword As Word.Application
        
        Set objword 
    = New Word.Application 'Creo el objeto word
        objword.Documents.Open "C:\Users\ggc\Desktop\Informe2.doc" '
    Abro el documento
        objword
    .Visible True
      
        objword
    .Selection.GoTo What:=wdGoToBookmarkName:=here
        objword
    .Selection.InsertAfter "link"
            
        
    objword.Selection.Hyperlinks.Add Anchor:=Selection.RangeAddress:= _
            
    "Informe.doc"SubAddress:=""ScreenTip:=""TextToDisplay:= _
            
    "link"
    End Sub 
    but the last sentence doesn't work. I've been looking for a solution but couldn't find anything similar, so I hope one of your expert excel minds may help me!!!
    thank you!!!!!

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: macro to create a hyperlink from excel to word document.

    Try (range is just an example)

    Please Login or Register  to view this content.
    or the English statement

    Please Login or Register  to view this content.
    Last edited by OllieB; 01-25-2013 at 05:56 AM.
    If you like my contribution click the star icon!

  3. #3
    Registered User
    Join Date
    01-25-2013
    Location
    seville
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: macro to create a hyperlink from excel to word document.

    Thanks you for your quick answer but sadly doesn't work. I mean, it pastes in the word document the selected area, but doesn't add the hyperlink I need.

  4. #4
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: macro to create a hyperlink from excel to word document.

    The range is pasted as a hyperlink (meaning that it refreshes etc), what kind of hyperlink do you want, do you want to click on it and open the Excel workbook etc? Because that is a different type of hyperlink.

  5. #5
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: macro to create a hyperlink from excel to word document.

    If you want a link to the Excel workbook

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-25-2013
    Location
    seville
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: macro to create a hyperlink from excel to word document.

    that's, I meant that kind of hyperlink which you click on it and opens another file, web site, etc. But it doesn't still work, excel says me: "wrong number of arguments or invalid property assignment"
    Maybe I do something wrong, my excel code is:
    PHP Code: 
    Sub escribe()
        
    Dim objword As Word.Application
         
        Set objword 
    = New Word.Application 'Creo el objeto word
        objword.Documents.Open "C:\Users\ggc\Desktop\Informe2.doc" '
    Abro el documento
        objword
    .Visible True
       
        objword
    .Selection.GoTo What:=wdGoToBookmarkName:="nombre"
        
    objword.Selection.InsertAfter "link"
        
    objword.Selection.Hyperlinks.Add Anchor:=Selection.RangeAddress:="C:\Users\ggc\Desktop\Informe.doc"SubAddress:=""ScreenTip:=""TextToDisplay:="name_that_you_want_to_show"
    End Sub 

  7. #7
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: macro to create a hyperlink from excel to word document.

    It looks like you are creating a hyperlink to another Word document ("C:\Users\ggc\Desktop\Informe.doc") in the Word document ("C:\Users\ggc\Desktop\Informe2.doc"), not to an Excel workbook. Irrespective, the instruction looks fine to me. Which line is highlighted as having the error?

  8. #8
    Registered User
    Join Date
    01-25-2013
    Location
    seville
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: macro to create a hyperlink from excel to word document.

    yep you were right, but I've just tried with an hyperlink to another excel and I've got the same problem. The line which causes the problem is:
    Please Login or Register  to view this content.
    I think the problem comes up from selection.range, but I'm not sure, cause I don't understand why, because the previous instructions write "link" and let it selected, so...

  9. #9
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: macro to create a hyperlink from excel to word document.

    Try

    Please Login or Register  to view this content.
    I think hyperlinks should be added to the document and not to the selection

  10. #10
    Registered User
    Join Date
    01-25-2013
    Location
    seville
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: macro to create a hyperlink from excel to word document.

    Ollie thank for all!!!!!!! but... doesn't work. I've tried with fresh word and excel documents and diferent extensions (you know, doc, docx, xlsm, xls, xlsx) but the error persists d'oh!! hahaha. Any suggestion? hahaha

  11. #11
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: macro to create a hyperlink from excel to word document.

    GOT IT!!!!!

    make the following change

    Please Login or Register  to view this content.
    without this Selection refers to the Excel workbook as opposed to the Word document!

  12. #12
    Registered User
    Join Date
    01-25-2013
    Location
    seville
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: macro to create a hyperlink from excel to word document.

    You're awesome!!!!!!!! that's!!!!! Thank you so much!!! it was driving me crazy!!!!

  13. #13
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: macro to create a hyperlink from excel to word document.

    Glad we were able to figure it out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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