Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Changing What Is Pasted in a Dialog Box.

Changing What Is Pasted in a Dialog Box

by Allen Wyatt
(last updated November 21, 2017)


Ihor wants to automate the inserting of a URL hyperlink into a Word document. The URL will be associated with a phrase, such as "click here". He first copies the URL of a specific website to the Clipboard. He then records a macro that opens the Insert Hyperlink dialog box (Ctrl+K) and pastes into the appropriate field the URL from the Clipboard (Ctrl+V) and clicks OK. When he later runs the macro, it gives him the same URL every time he runs it. Ihor wants to paste a different URL into the dialog box every time he runs the macro, but seems to be missing how to do that.

When you record a macro, it is very literal about what it does—it records exactly the steps you take, including how dialog boxes are filled out. The solution isn't to look for ways to paste new information into a dialog box, but to look at how you are creating your hyperlink. Here's what would be recorded if you inserted a hyperlink with the macro recorder running:

Sub Macro1()
' Macro1 Macro
    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
        "", SubAddress:="", ScreenTip:="", TextToDisplay:= _
        "click here"
End Sub

What Ihor wants to change is the target for the hyperlink, which is assigned to the Address property; this is what gets "pasted" into the Address field of the dialog box. In order to do this, you could change your macro in a simple manner, such as this:

Sub Macro2()
    Dim sTemp As String
    sTemp = ""

    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= sTemp, _
        SubAddress:="", ScreenTip:="", TextToDisplay:= "click here"
End Sub

All that has been done in this example is delete some of the unnecessary comments at the beginning of the macro and create a string variable, sTemp, that now contains the target for the hyperlink. This variable is then assigned to the Address property. In order to change the target, then, one only needs to change the value of the sTemp variable—and there are a number of ways this can be done.

One way is to use an InputBox function to create your own dialog box, in this manner:

Sub Macro3()
    Dim sTemp As String
    Dim sPrompt As String
    Dim sTitle As String

    sPrompt = "Enter the target for the hyperlink"
    sTitle = "Hyperlink Destination"
    sTemp = ""
    sTemp = InputBox(sPrompt, sTitle, sTemp)

    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= sTemp, _
        SubAddress:="", ScreenTip:="", TextToDisplay:= "click here"
End Sub

Of course, Ihor mentioned that in his process he actually copies the URL to the Clipboard. If that is the process that he wants to use, it is possible to assign the URL based on whatever is in the Clipboard when the macro is run. Here's how you would do that:

Sub Macro4()
    Dim sTemp As String
    Dim MyData As DataObject
    Set MyData = New DataObject

    sTemp = Trim(MyData.GetText(1))

    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= sTemp, _
        SubAddress:="", ScreenTip:="", TextToDisplay:= "click here"
End Sub

In order to utilize the Clipboard in this manner, you'll need to set up a reference for the Microsoft Forms in the VBA Editor. (Choose References from the Tools menu in the Editor.)

Note, as well, that all these examples modify what is assigned to the Address property of your new hyperlink. There is a good chance that you'll want to change the macro to modify what is assigned to the TextToDisplay property, as well.


If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (138) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Changing What Is Pasted in a Dialog Box.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...


Quickly Switching Between Spreadsheet Windows

Using the keyboard to switch between Excel spreadsheets.

Discover More

Delivery Address Won't Print on Envelopes

Word includes a feature that allows you to easily create and print envelopes, based on the addresses you insert in your ...

Discover More

Applying Bullets from the Keyboard

Most people use the tools on the Home tab of the ribbon to apply bullets to paragraphs. If you want to apply them using ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (menu)

Displaying the Document Title Right Away

One of the properties that Word maintains for a document is a title. If you want this title displayed on the title bar ...

Discover More

Printing via Macro without Messages

When you are printing a document, it is not unusual to see messages (dialog boxes) periodically. When you want the ...

Discover More

Printing Summary Information from a Macro

Part of the information that Word maintains about each of your documents is a summary statement, which you can define in ...

Discover More

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 + 8?

2015-06-18 07:01:24

Alex Vera

Help me , tell me the secueancias need to copy and paste the hyperlink that is on the clipboard. I sent what I 've done.

In the example of Macro 4 it is what I want but not how to add it to my macro. Thank you.

Sub Macro1()
' Macro1 Macro
With Selection.Find
.Text = "Go to store"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
ActiveDocument.DefaultTargetFrame = ""
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
"", SubAddress _
:="", ScreenTip:="", TextToDisplay:="Ir a tienda/Go to store", Target:= _
End Sub

2014-09-08 23:19:32

Scott Morris

This is an excellent tip. I have a quick question about it. I want to create a hyperlink from the selected text but the hyperlink will be a calculated string of <URL>+<SelectedText>. How do I identify the selected text as a variable in the macro?

For example, I have a ticket number, 123456, in my document. I want that ticket number to be a link to a ticket system that is a fixed URL ending in the ticket number. http://ticketsystemURL&ticketnumber.

This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Newest Tips

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.