![how to create a hyperlink in word programmatically how to create a hyperlink in word programmatically](https://www.computerhope.com/issues/pictures/msword-insert-hyperlink.jpg)
How to create a hyperlink in word programmatically code#
If the hyperlink is equal to, we then use this line of code to retarget the link to the Script Center instead: objHyperlink.Address = “”Īnd then we loop around and check the next link in the collection. If Address isn’t equal to we skip that hyperlink, loop around, and continue the process with the next item in the collection.
![how to create a hyperlink in word programmatically how to create a hyperlink in word programmatically](https://www.get-digital-help.com/wp-content/uploads/2012/07/List-all-file-names-in-current-folder-as-hyperlinks.gif)
Inside that loop we use the following line of code to see if the Address property (the property representing the hyperlink target) is equal to : If objHyperlink.Address = “” Then Once we have the collection in hand we set up a For Each loop to loop through each hyperlink in the collection. So how do we go about changing these hyperlinks? Well, to begin with, we use this line of code to retrieve a collection of all the hyperlinks in the document: Set colHyperlinks = objDoc.Hyperlinks But that’s probably because they know that the Scripting Guys would never sell. No, Google has not offered us $1.6 billion for the Script Center, at least not yet. That, of course, is the home page why the heck would anyone want to go there? Consequently, we need our script to locate all instances of this particular hyperlink and change the target address to the Internet’s true hot spot.
![how to create a hyperlink in word programmatically how to create a hyperlink in word programmatically](https://tipsmake.com/data/thumbs/how-to-insert-a-hyperlink-in-microsoft-word-thumb-K3zxmlsXO.jpg)
As it turns out, Test.doc happens to have several hyperlinks pointing to. With Word up and running we then use the Open method to open the document C:\Scripts\Test.doc. For educational purposes, however, we’ve always found it better if people can watch as the excitement unfolds.) (Of course, you don’t have to see Word onscreen in order to change a hyperlink. Set objDoc = (“c:\scripts\test.doc”)Īs you can see, we start out by creating an instance of the Word.Application object we then set the Visible property to True, giving us a running instance of Microsoft Word that we can see onscreen. As it turns out, PH, this is your lucky day after all, we just happened to have a script that can change an existing link in a Microsoft Word document: Set objWord = CreateObject(“Word.Application”) (Which would definitely be true if you were the one cooking the dinner.) However, superstitions involving Friday the 13 th seem to be a modern phenomenon no references to Paraskevidekatriaphobia (or anything simlar) can be found prior to the 20 th century.īut, like we said, this is all superstitious nonsense. (Although we should note that Peter Costantini, the oldest living Scripting Guy, says he remembers the two biting into the apple on a Wednesday morning.) Likewise, the number 13 has long been considered an unlucky number many ancient cultures believed that it was unlucky to invite 13 people to dinner. Fridays have long been considered unlucky according to tradition, Adam and Eve took their fateful bite of the apple on a Friday. For example, people who suffer from Paraskevidekatriaphobia (a debilitating fear of Friday the 13 th) would never ask the Scripting Guys a question on this day: they’d be too afraid that we’d give them a script that didn’t work, that we’d write a column that didn’t make sense, or that we’d blabber on and on about some arcane trivia that has nothing to do with scripting or with the question they asked. You know, we’re impressed that you had the guts to ask a question today after all, today is Friday the 13 th, a date many people dread, fearing that anything bad that could happen will happen.
![how to create a hyperlink in word programmatically how to create a hyperlink in word programmatically](https://docs.devexpress.com/WindowsForms/images/richeditcontrol_hyperlinks_result128291.png)
Hey, Scripting Guy! How can I change an existing hyperlink in a Microsoft Word document?