問題描述
從顯示“錯誤!超鏈接引用無效”的 MS Word 字段中恢復 URL (Recover URL from MS Word fields showing "Error! Hyperlink reference not valid")
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:
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
方法 2:
How about:
For Each oHyperlink In ActiveDocument.Hyperlinks
set rng = oHyperlink.Range
rng.Collapse wdCollapseStart
rng.text = oHyperlink.TextToDisplay
oHyperlink.Range.Delete
Next oHyperlink
方法 3:
I just had the same problem and worked around the problem by opening the document with LibreOffice.
I'm sorry I could not find anything in options of Word to open or revert this (Word v16.61 on MacOS 12).
(by Gineer、Anthony Lewis、Tom Hillman、Thomas Baeckeroot)