Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Your site has saved me hours of work that I cannot begin to express my satisfaction..."

Geography

Where in the world do Tek-Tips members come from?
Bill4tektips (TechnicalUser)
29 Jun 12 8:39
I have a word document with about 700 hyperlinks to various documents within a WSS site and now they have changed the address of the WSS site.
I have tried doing a "Show Field Codes" and doing a Find and Replace but when I undo Show Field Codes and hover over the links they are still showing the old address but the field codes show the new address. I am trying to change from http://cyscoshare/ to http://cyscoshare05/. Can anyone help?
kjv1611 (TechnicalUser)
29 Jun 12 11:17
Well, just go through, change each one, link by link, and take a coffee break between each change. Will that work? wink

Okay... up front, the below is done in VBA.. if you are uncomfortable with it, and need more help than what I put here, post back with more questions, and I or someone else can guide you through this - this one should be simple enough to knock out with VBA in a matter of seconds.

Try something like this (just tested to look at - using VBA):

CODE

Sub TestSearchLink()
    Dim x As Hyperlink
    MsgBox ThisDocument.Hyperlinks.Count
    For Each x In ThisDocument.Hyperlinks
        If InStr(x.Address, "google") Then MsgBox "Howdy!"
    Next x
End Sub 

That's just to search through it, so to change it, you could use Replace in there... so...

CODE

Sub TestChangeLink()
    Dim x As Hyperlink
    MsgBox ThisDocument.Hyperlinks.Count
    For Each x In ThisDocument.Hyperlinks
        If InStr(x.Address, "google") Then MsgBox "Howdy!"
        x.Address = Replace(x.Address, "google", "msn")
        MsgBox x.Address
    Next x
End Sub 


To test the above, with a blank Word Document, I added "Test Search My Link", and then linked that text to http://www.google.com

The code you have to put in the particular Word Doc in order to use the "ThisDocument" object. You could use a more general document object if you want to put it in Normal.dot or Normal.dotx.

So give it a whirl, change to suit your needs, and post back with your progress.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57

macropod (TechnicalUser)
29 Jun 12 19:40
After doing the Find/Replace, you could run the following macro:

CODE --> VBA

Sub UpdateHyperlinkDisplay()
Dim HLnk As Hyperlink
For Each HLnk In ActiveDocument.Hyperlinks
  HLnk.TextToDisplay = HLnk.Address
Next
End Sub 

Cheers
Paul Edstein
[MS MVP - Word]

Bill4tektips (TechnicalUser)
2 Jul 12 2:46
kjv1611, Thanks for that but when I try it it just comes up with a Microsoft Word box with "O" in it. Even when I try a Test document linked to Google I am getting the same result. I am not a confident user of VBA so any help would be appreciated from anyone.
macropod (TechnicalUser)
2 Jul 12 2:56
Have you tried the code I posted?

Cheers
Paul Edstein
[MS MVP - Word]

Bill4tektips (TechnicalUser)
2 Jul 12 3:18
Paul, Yes I tried it but I just got "Run-time error '5824' Method 'TextToDisplay' of object 'Hyperlink' failed"
MakeItSo (Programmer)
2 Jul 12 4:30
@kjv: If I'm not mistaken, "ThisDocument" refers to the document containing the code which in this case would be Normal.dot. Plus: I wouldn't want to click 700 messageboxes. tongue
@Paul: if Bill mixed your code with kjv's the wrong way, that might be the cause.

@Bill: try running this:

CODE

Sub ChangeAddresses
Dim hl As Hyperlink

For Each hl In ActiveDocument.Hyperlinks
    If InStr(1, hl.Address, "http://cyscoshare/") > 0 Then
        hl.Address = Replace(hl.Address, "http://cyscoshare/", "http://cyscoshare05/")
        hl.TextToDisplay = hl.Address
    End If
Next

End Sub 

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

Bill4tektips (TechnicalUser)
2 Jul 12 5:04
MakeItSo, Yes that works, BUT it strips out the link words and replaces them with the Hyperlink. So what was "VJ0402A----XAA" becomes "http://syscoshare05/sysco/Data_Sheets/Shared%20Doc..." but we need to show the link word not the full address.
Helpful Member!  MakeItSo (Programmer)
2 Jul 12 6:45
I see.
Just leave away this line from the code:

CODE

hl.TextToDisplay = hl.Address 

So that it becomes this:

CODE

Sub ChangeAddresses
Dim hl As Hyperlink

For Each hl In ActiveDocument.Hyperlinks
    If InStr(1, hl.Address, "http://cyscoshare/") > 0 Then
        hl.Address = Replace(hl.Address, "http://cyscoshare/", "http://cyscoshare05/")
    End If
Next

End Sub 

P.S: I hope you are making backups... tongue

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

Bill4tektips (TechnicalUser)
2 Jul 12 6:49
MakeItSo: Yes that works perfect. Thank you for your Patience.
kjv1611 (TechnicalUser)
2 Jul 12 12:58
ThisDocument does reference the doc in which the code resides. My assumption was that the code wouldn't be something the user would want to use on multiple docs, but rather the doc in question. So in that case, they would put the code inside the document that has all the links, run the code, then be done with it. But yes, if I were to use it myself, I'd likely prefer to have it available at any time for any doc, and would use ActiveDocument instead. smile

I did specify that in my original post:

Quote (me)

The code you have to put in the particular Word Doc in order to use the "ThisDocument" object. You could use a more general document object if you want to put it in Normal.dot or Normal.dotx.

And InStr(1, hl.Address, "http://cyscoshare/") > 0

vs

InStr(1, hl.Address, "http://cyscoshare/")

will give the same results.

I suppose the "O" message came in where the user put the code under Normal.Dot(x) instead of the current file.

glad it worked out.

One other note of clarification: Bill4tektips didn't ask to replace the displayed text with the link, but it was given. When that example was given, Bill simply added it to the code. Then Bill said he didn't want it after all, which wound up with a different variation of the original code.

In the end, hopefully Bill4tektips learned something of future value. thumbsup2

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close