PDA

View Full Version : Solved: Extracting Hyperlinks



Alasbabylon
06-22-2009, 11:59 AM
I have a large list of documents copied from a Web page and each document has a hyperlink to the document on the server. How do I take my list, keep the document name, but extract the hyperlink from the title and put it on a line below the title? For example, I may have 150 document titles for one folder, each title having a hyperlink to the actual document. So, if My Primary Training Book.pdf is one line in my table, I'd like to extract the hyperlink, add a line return at the end of the title and paste in the hyperlink in the same cell. I would then have:
My Primary Training Book.pdf
https:\\server_location\Folder\folder\My Primary Training Book.pdf
Can I do that?

Oorang
06-22-2009, 12:17 PM
Hello,
I think perhaps some clarification would be in order. When you say you have a large list of documents does that mean you have a word file with a list of file paths to documents? What types of files can the paths be to? When you say "title" do you mean the file name, a value in the header, the first text line of the document etc?

fumei
06-22-2009, 12:42 PM
"I'd like to extract the hyperlink, add a line return at the end of the title and paste in the hyperlink in the same cell."

No need to extract and paste anything whatsoever.
Sub AddressAfterHyperlink()
Dim oHyper As Hyperlink
Dim r As Range

For Each oHyper In ActiveDocument.Hyperlinks
Set r = oHyper.Range
r.InsertAfter Text:=vbCrLf & oHyper.Address
Next
End Sub
NOTE! This will not, repeat NOT, put any text if the hyperlink address is a bookmark in the same document.

Hyperlinks to bookmarks in the same document are SubAddress, not Address.

fumei
06-22-2009, 12:53 PM
Although, I admit I have the same questions as Oorang asked. I do not know what you mean by "title". Please try and be clear when you ask things.

"I may have 150 document titles for one folder"

My bolding.

Folder? What folder? It sounds like you are talking about a bunch of hyperlinks in a document. So...what folder?

It may mean something to you that these are "document titles", but please remember that to Word it is just text that are hyperlinked to something.

Demo of my first post attached. The procedure uses a keyboard shortcut Alt-a. So press Alt-A, and - voila! - your address will be inserted after the hyperlink.

Alasbabylon
06-23-2009, 11:07 AM
SOLVED! THank you SO much! This will save me so much frustration! I really appreciate the thelp, especially since I was evidently not very clear about what I was trying to accomplish.

Oorang
06-23-2009, 12:54 PM
Nice work:)

fumei
06-23-2009, 01:31 PM
I just want to point out that it is possible that you may get "incorrect" data out of Address. Word has the annoying habit of changing URL addresses behind your back, if the URL is a network address (not an internet address). Make sure the original address is fully UNC.

If they are Internet addresses, this is not a problem. Http(s) addresses are stored just as they are.