Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Location
    Durham, North Carolina, USA
    Posts
    140
    Thanks
    5
    Thanked 1 Time in 1 Post

    Convert hypertext to links

    Hi folks,

    I have 71 pages worth of text like this:


    http://biolink.biocryst.com/livelink/livelink.exe/Open/100607

    in a Word document, with each line a separate paragraph. My author would now like each one linked to its path. Is there a quick easy way to do this in W2007?

    My thought was to write a macro to select each paragraph, convert that paragraph to a hyperlink using the selected text as the Address, and then repeat with the next paragraph, but I can't figure the right way to write the code.

    Thanks in advance...

    Beej


  2. #2
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts
    Hello Beej

    You could try something like this. No guarantees but it might get you started.
    You might need to ensure that there is a trailing slash at the end of your example.
    Geof
    ---------------
    Sub create_HLink()
    Dim hlnk As Hyperlink
    Dim oPara As Paragraph
    On Error GoTo errorHandler
    For Each oPara In ActiveDocument.Paragraphs
    oPara.Range.Select
    If Selection.Characters.Count > 1 Then
    ActiveDocument.Hyperlinks.Add Selection.Range, Selection.Range
    End If
    Next
    Exit Sub
    errorHandler:
    MsgBox ("Error numbered " & Err.Number & Chr(13) & Err.Description)
    End Sub

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Beej

    There is a built-in command to do this but it is pretty hard to find in Word 2007 and Word 2010. I only have 2010 loaded so I will explain how to find the command in that version and the basic workflow will be the same in Word 2007.

    The command is called AutoFormat and you need to add it to your Quick Access Toolbar.
    1. Click on the dropdown arrow at the end of the QAT and choose More Commands (it may be Customize in v2007)
    2. In the customize dialog, choose commands from All Commands
    3. Find the entry for 'AutoFormat...' and put this in your QAT
    4. Click the OK button to close the customize dialog
    5. Now click the new button on your QAT (it has a lightning bolt over a document)
    6. In this Autoformat dialog, go into your options and turn on the 'Internet and network paths with hyperlinks' setting
    7. OK out of the dialogs and the links should now be enabled
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. The Following User Says Thank You to Andrew Lockton For This Useful Post:

    pjustice57 (2011-03-23)

  5. #4
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts
    Thanks Andrw
    I had totally forgotten about AutoFormat since 03

  6. #5
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    With good reason I would think Geoff. The only thing I use that command for normally is to turn on smart quotes.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  7. The Following User Says Thank You to Andrew Lockton For This Useful Post:

    itsjustb (2011-03-29)

  8. #6
    2 Star Lounger
    Join Date
    Jun 2002
    Location
    Durham, North Carolina, USA
    Posts
    140
    Thanks
    5
    Thanked 1 Time in 1 Post
    Thank you both! Andrew, I used Geof's code before I saw your post. Oh well. I'll chalk it up as a chance to practice my VBA, which I don't often get to do anymore.

    Geof, fyi, the code worked but it need one tweak. The code as written also selected the paragraph mark at the end of each line, and Word tried to include it in the path (at least, that's what I think was happening). Bottom line, it didn't work if that para was selected. I modified the code to deselect the para symbol:

    Sub Converttohyperlink()

    Dim hlnk As Hyperlink
    Dim oPara As Paragraph
    On Error GoTo errorHandler
    For Each oPara In ActiveDocument.Paragraphs
    oPara.Range.Select
    If Selection.Characters.Count > 1 Then
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    ActiveDocument.Hyperlinks.Add Selection.Range, Selection.Range
    End If
    Next
    Exit Sub
    errorHandler:
    MsgBox ("Error numbered " & Err.Number & Chr(13) & Err.Description)
    End Sub

  9. #7
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts
    Hi
    Thanks for the feedback.
    We have both learned something. I enjoy reading the posts and had forgotten about the Autoformat.
    I love this lounge for that very reason.
    Lounge members have helped me a lot over the years. It is nice to give a little back when I can.

    Geof

Posting Permissions

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