views:

713

answers:

2

I have some word documents that have place holder URL's in them. The URL's are something like "http://<URL>/service.svc". Word has figured that these have to be a valid URL and when the fields get updated, replace them with "Error! Hyperlink reference not valid".

When I mouse over that error text, word pop's up a tooltip still showing the original text. Is there some way to extract the original text? The document is over 80 pages in length. Surely there must be a programmatic way to do this?

I've tried the following code, but it does not seem to find the Hyperlinks in question.

        For Each oHyperlink In ActiveDocument.Hyperlinks
        If IsObjectValid(oHyperlink) Then
            If Len(oHyperlink.Address) > 0 Then
                If Mid(oHyperlink.Address, 8, 5) = "<ULR>" Then
                    oHyperlink.TextToDisplay = oHyperlink.Address
                    oHyperlink.Range.Font.Color = wdColorBlue
                    oHyperlink.Range.Font.Underline = wdUnderlineSingle
                    oHyperlink.Range.Font.UnderlineColor = wdColorBlue
                End If
            End If
        End If
    Next oHyperlink

If in the above code sample you remove the line which tests if the item IsObjectValid it comes back with a load of hyperlink stating "Object has been deleted". I'm assuming this could be the broken (by word) "Hyperlinks". How do I get my text back?

Note: This document has been saved and closed so Ctr+z is not an option.

The information is in there, how do I get it?

+1  A: 

Have you tried opening the file with Notepad and searching for http? This works for me.

You can also use a program like "strings" to get all of the text strings from the Word file. See http://technet.microsoft.com/en-us/sysinternals/bb897439.aspx

Anthony Lewis
That's what I ended up doing (Notepad). I was just hoping that there would be some way to programatically revert the screw-up that word created back to what it was supposed to be. I'm always wary of too much human intervention, since us humans are known to have finger problems and the like.
Gineer
I'd still like to know if there is a real programatic answer to this, because I'm sure this is not the last time this will happen.
Gineer
A: 

How about:

For Each oHyperlink In ActiveDocument.Hyperlinks
    set rng = oHyperlink.Range
    rng.Collapse wdCollapseStart
    rng.text = oHyperlink.TextToDisplay
    oHyperlink.Range.Delete
Next oHyperlink
Tom Hillman