Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Jan 2010
    Location
    North Carolina
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Find/Replace hyperlinks in Word 2013

    I frequently copy sections of text from the internet that contains hyperlinks. However, in some cases the hyperlink field does not contain a single space before or after so that the text runs together. For example, “this is a hyperlinkwith no space afterwards”. Unless the hyperlink field begins a sentence, it should have a space before it. It may be followed by a by a period, comma, or other punctuation but otherwise followed by a space.

    I do not wish to change the hyperlink or any of its 3 fields. I just wish to place the space where needed before or after it.

    I’m using Word 2013. I can find the hyperlink using the ^19 or ^21 but can’t find a way to use wildcards to select leading or following characters. I’ve tried with and without field view (Alt-F9) active. I can even find the field beginning, {, and end, }, characters but still no wildcards.
    Can anyone think of a way to do this with Find/Replace? Could it be done with a VBA sub app? I’m not skilled in VBA but can muddle my way using examples most of the time.

    I would appreciate your help.

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,945
    Thanks
    0
    Thanked 203 Times in 184 Posts
    You could use a macro like:
    Code:
    Sub Demo()
    Dim HLnk As Hyperlink
    For Each HLnk In ActiveDocument.Hyperlinks
      With HLnk.Range
        If Not .Characters.First.Previous Like "[( " & Chr(9) & Chr(11) & Chr(12) & vbCr & "]" Then .InsertBefore " "
        If Not .Characters.Last.Next Like "[ !:;,.?)" & Chr(9) & Chr(11) & Chr(12) & vbCr & "]" Then .InsertAfter " "
      End With
    Next
    End Sub
    In addition to testing for spaces, the above code permits a variety of other characters before/after.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    New Lounger
    Join Date
    Jan 2010
    Location
    North Carolina
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the quick response. I've tried the macro but I get "Run time error '91'; object variable or with block not set". It seems that I know less that I thought about macros. I don't know what variable to set. -b

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,945
    Thanks
    0
    Thanked 203 Times in 184 Posts
    The macro works fine in my testing, so I'm not sure what the issue is. Try copying & pasting from my last post & running it again. If it still doesn't work, attach a document to a post with some representative data (delete anything sensitive) and I'll test further with your data. You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    New Lounger
    Join Date
    Jan 2010
    Location
    North Carolina
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I deleted it all and took it to Word 2010 my other PC. Your macro worked perfectly! I brought it back to Word 2013, re-entered and it worked perfectly. I did not see my error but the wipe and redo must have fixed the problem. I really appreciate the macro that you have provided. It solved my immediate problem and also gives me a new technique that I can use, with variations, in my macros. Thanks so much for your help.

  6. #6
    New Lounger
    Join Date
    Jan 2010
    Location
    North Carolina
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Find/Replace hyperlinks in Word 2013 Follow-up

    In the closed thread, “Find/Replace hyperlinks in Word 2013” at http://windowssecrets.com/forums/sho...ght=hyperlinks. macropod provided an excellent macro to do the find/replace. However, the macro fails with the following error:
    “Microsoft Visual Basic; Run-time error 4680:; That property is not supported for this object”
    when the macro encounters a graphic (jpg, png, etc) which has a hyperlink.

    Is there a way to just skip graphics associated with a hyperlink and continue the macro?

  7. #7
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,945
    Thanks
    0
    Thanked 203 Times in 184 Posts
    You could insert 'On Error Resume Next' before 'For Each HLnk In ActiveDocument.Hyperlinks'.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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