MacroFilter: I am trying to make a code snippet for Word work and don't understand why it's not working.
September 10, 2011 10:19 PM Subscribe
MacroFilter: I am trying to make a code snippet for Word work and don't understand why it's not working.
I want to extract hyperlinks from a Word 2007 document where links have been pasted as text. For example, if I pasted text from a webpage and all the links appeared as "click here", I want to get the value of the URL from those links.
This link sounds like it will do the job quite nicely:
http://technet.microsoft.com/en-us/library/ee692879.aspx
Here is what I have:
---------------------
Sub LinkExtractor()
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Open("c:\users\calzephyr\desktop\links.docx")
Set colHyperlinks = objDoc.Hyperlinks
For Each objHyperlink In colHyperlinks
Wscript.Echo objHyperlink.Address
Wscript.Echo objHyperlink.TextToDisplay
Next
End Sub
-----------------------
I found out about it from this page, where other snippets were posted, but don't seem to work for me either:
http://www.yourbloghelper.com/2008/12/07/how-to-extract-urls-from-ms-word-2007-hyperlinks/
I think I'm just not seeing where I could be going wrong - can anyone lend me their thoughts as well as their eyeballs? I am wondering if something is missing from the script or if it is not clear that the macro exports the links to another file rather than to itself.
posted by Calzephyr to computers & internet (10 answers total) 3 users marked this as a favorite
posted by doublehappy at 11:37 PM on September 10, 2011