Word link with spaces

When you are typing a document, Microsoft Word recognizes certain values, such as Web and UNC addresses (a
network resource), and automatically makes them hyperlinks. However, after you enter a space, Word stops
creating the hyperlink because it has no way of knowing whether you’ve finished the address and are now
typing another word or whether the address contains spaces.

To manually specify that a group of words containing spaces is an address and should be represented by a
hyperlink, simply surround the text with the left and right angle brackets:

Prefix the address with the < character and terminate it with the > character. For example, how to
use the angle brackets to discern a Web address:

<http://www.example of an address with spaces.html>.

Hyperlink in Word 2016

A second way of entering an address with spaces that should be treated as a hyperlink is to insert the
value %20 (the hex value for a space symbol) for each space. Using this technique, the previous example address
would be entered as follows:

http://www.example%20of%20an%20address%20with520spaces.htm.

Hyperlink2 in Word 2016

Note: See also Use
hyperlink without holding Ctrl.

See also this tip in French:
Comment entrer un lien hypertexte contenant un espace dans un document Word.

Please, disable AdBlock and reload the page to continue

Today, 30% of our visitors use Ad-Block to block ads.We understand your pain with ads, but without ads, we won’t be able to provide you with free content soon. If you need our content for work or study, please support our efforts and disable AdBlock for our site. As you will see, we have a lot of helpful information to share.

As you type, Word recognizes certain sets of characters, such as web and UNC (Universal Naming Convention — a network resource) addresses, and automatically converts them to live hyperlinks. However, you may notice that addresses with spaces are not converted correctly.

After the first space in the address is encountered, Word stops creating the live hyperlink because it doesn’t know whether you are finished typing the address and continued on the next word or if the address contains spaces. However, there are a couple of easy solutions for this problem.

The first way to specify that a group of words containing spaces is a web or UNC address you want to converted to a live hyperlink, is to surround the text with the left (<) and right (>) angle brackets, as pictured below.

When you press the “Space Bar” or the “Tab” key after the closing bracket, Word converts the address in the brackets to a live hyperlink.

NOTE: You can also surround the address with quotes.

Another method is to replace each space in the address with “%20” (without the quotes), which is the hex value for a space.

Again, when you press the “Space Bar” or the “Tab” key after the end of the address, Word converts the address to a live hyperlink. Notice that the hex value for a space remains in the hyperlink. It is still a valid hyperlink.

You can apply the same methods to UNC addresses to convert them to live hyperlinks as you type, as shown below.

If you have an address containing spaces that did not convert correctly, you can fix it without retyping it. Simply right-click on the part of the address that is a hyperlink and select “Remove Hyperlink” from the popup menu.

Then, add the brackets or quotes on either end of the address and enter a space or tab after the closing bracket or quote. The address will be converted to a live hyperlink. This last tip is especially useful if you have some long addresses you need to fix but don’t want to retype.

You can also remove hyperlinks from some or all web or network addresses in your document. If you don’t want to create live hyperlinks automatically from web or network addresses, you can disable the automatic creation of hyperlinks.

These tricks for entering live hyperlinks also work in Outlook.

READ NEXT

  • › Android’s Nearby Share Has (Unofficially) Arrived on Mac
  • › The New Winamp Is Here, but It’s Not What You’d Expect
  • › Save Hundreds on Elegoo’s New PHECDA Laser Engraver Through Kickstarter
  • › How to Get a Refund on the PlayStation Store
  • › Discord Direct Message Won’t Go Away? Here’s the Fix
  • › Windows 11 Has a New Photo Gallery in the File Explorer

How-To Geek is where you turn when you want experts to explain technology. Since we launched in 2006, our articles have been read billions of times. Want to know more?

While hanging out in the PowerShell forums, I came across a question that talked about going out to a Sharepoint site and finding all word documents and then scanning each document and fixing all of the hyperlinks that had spaces in it. While I didn’t provide the answer for connecting to Sharepoint, I was able to help the user out with opening up and fixing any hyperlinks with spaces.

This example word document has three hyperlinks in it, 2 are valid and 1 is using a link that has spaces in it.

image

The first step in this is to connect to the word document using the Word.Application COM object.

$word = New-Object -ComObject Word.Application
$document = $word.documents.open("C:usersadministratordesktopTEST.docx")

Finding all of the hyperlinks is actually very simple using the hyperlinks property.

image

We can tell from the image that the last hyperlink has some spaces in it that need to be updated. But there is a gotcha to this that I will show a little later on. But first, how am I going to fix the hyperlink? I could use regex or a replace method for the space, but that just seems like a little too much for something like this. Fortunately, we can use the System.URI class to make this conversion without any hassle.

([uri]"http://domain.com/This is a bad link").AbsoluteUri

image

Perfect! Now we can work on making the updates to the bad hyperlink or hyperlinks, if applicable.

$hyperlinks = @($document.Hyperlinks) 
$hyperlinks | ForEach {
    If ($_.Address -match "s") {
        $newURI = ([uri]$_.address).AbsoluteUri
        Write-Verbose ("Updating {0} to {1}" -f $_.Address,$newURI) -Verbose
        $_.address = $newURI
    }
}
$document.save()
$word.quit()

image

You will notice that I had to wrap the $document.hyperlinks in “@()” to make it an array. There is a quirk when working with COM objects in that even though you may have multiple outputs that resemble a collection, it does not behave like a collection in the way that you can iterate through each of the objects or even pull a specific item using array slicing. By forcing it into a collection of objects.

Now that I have finished this up, lets look at that hyperlink again.

image

All fixed! All seems great, however, the gotcha that I was talking about is that if you hover over the hyperlink, it still looks like it just has spaces in it.

image

Another interesting thing is that even when looking at the link via PowerShell, you will see that it doesn’t show the “%20” that you would expect to see and instead shows spaces still.

image

This is important to note when running this code as it will always attempt to “fix” the hyperlink. I am not completely sure why it doesn’t show up correctly even when viewed through PowerShell, but I would assume it is another quirk of working with the word COM object.

Hope that this helps out those that have come across this issue and wanted an automated solution to fix it!

This entry was posted in powershell and tagged hyperlink, Powershell, word. Bookmark the permalink.

INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Thanks. We have received your request and will respond promptly.

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It’s Free!

*Tek-Tips’s functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Opening a link (with spaces) in word

Opening a link (with spaces) in word

(OP)

23 Mar 09 09:49

Hi

I am trying to create a link that will open in Word, but I am already out of my depth….

I have a table that lists Customer ID’s and a path to a word document:
S:Customer DocumentsCustomer Information FilesGosport Loaders [G1] CIF.doc

I then select that using a SQL statement:

CODE

strSQL2 = «select Replace(FileName1, ‘ ‘, ‘%20’) from sikbase..KnowledgeBase where custid = ‘» & CustID & «‘»
rsData2.Open strSQL2, MyConn

As you can see, I have tried to allow for the spaces with %20, but in IE it also replaces the % with %2520 !

I then display the result:

CODE

<%if rsData2.eof then%>
<FONT SIZE=»+1″ COLOR=»RED»>There is no CIF Link available.</FONT>
<%else%>
<table border=’0′>
<%Do While not rsData2.EOF
    Response.Write «<tr>»
    for each fieldItem in rsData2.fields
    Response.Write «<td><a href=» & fieldItem.value & «>Link Here to Word Doc</a></td>»
    next
    Response.Write «</tr>»
    rsData2.MoveNext
Loop%>
</table>
<%end if%>

Despite all that, it will not open the link, where am I going wrong (apart from believing that I can write ASP and HTML code)

Many thanks

Jonathan
www.telecom-stuff.com
 

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Join Tek-Tips® Today!

Join your peers on the Internet’s largest technical computer professional community.
It’s easy to join and it’s free.

Here’s Why Members Love Tek-Tips Forums:

  • Tek-Tips ForumsTalk To Other Members
  • Notification Of Responses To Questions
  • Favorite Forums One Click Access
  • Keyword Search Of All Posts, And More…

Register now while it’s still free!

Already a member? Close this window and log in.

Join Us             Close

RRS feed

  • Remove From My Forums
  • Question

  • Word 2007 won’t allow the creation of hyperlinks with spaces or %20. The OK button in the hyperlink dialog box becomes disabled as soon as a %20 is added to the hyperlink address.

    For example…  «http://www.pubplace.com?doc=My» is fine but… «http://www.pubplace.com?doc=My%20Doc»

    … no can do.

    We have two copies of Word 2007 and both have this problem. Word 2010 seems to work fine.

    Any ideas? 

All replies

  • Hi,

    Try to use <> to make the link in it.

    For example:

    <http://www.micro soft.com>

    Then the OK button will not disabled. Click the OK button, then it will done.


    Jaynet Zhang

    TechNet Community Support

    • Edited by

      Thursday, June 7, 2012 5:21 AM

    • Marked as answer by
      Jaynet Zhang
      Monday, June 11, 2012 1:28 AM
    • Unmarked as answer by
      Jaynet Zhang
      Tuesday, June 19, 2012 1:18 AM

  • Thanks for the reply. For some reason, that doesn’t work for me.

    The OK button stays enabled until I put the closing >, then it disables.

    For example, I can choose OK for «<http://www.micro soft.com» but not for «<http://www.micro soft.com>» 

  • Hi,

    Now I tried this both in my Word 2007 and Word 2010, it doesn’t work.

    I also tried to used macro to do this, but if the hyperlink contains spaces, it will show “Error, hyperlink not vaild…”.

    So I think the only way is type in the link with <>in the document directly, then press Enter key.

    Then the link will show, but the display text cannot be changed.


    Jaynet Zhang

    TechNet Community Support

    • Marked as answer by
      Jaynet Zhang
      Tuesday, June 19, 2012 1:18 AM
    • Unmarked as answer by
      Jaynet Zhang
      Monday, July 16, 2012 1:45 AM

  • I can create a hyperlink in Word 2007 containing spaces by typing <> around the url BUT the hyperlink doesn’t work — Ctrl click does nothing.

    Digging deeper I can see that Word creates an invalid hyperlink with no target URL…I looked in the Word doc XML and the hyperlink is invalid — it has no relationship (there should be a r:id attribute on the w:hyperlink)….

    <<w:hyperlink w:history1«>

    —   <w:r w:rsidRPr001B6FD9«>

    …..

            <w:t>http://pubplace.PubPlace.com?folder=Word
    and PDF
    </w:t>

      </w:r>

    </w:hyperlink>

    Anyway, I can’t believe that Word 2007 can’t create a hyperlink with spaces. Nobody does this???? Looking on the web there seems to be some guides on how to do it — seems it works for some people — or did at some point…

Понравилась статья? Поделить с друзьями:
  • Word link to internet
  • Word link text to other text
  • Word link image with text
  • Word lines in margin
  • Word lines for writing on the wall