?
Solved

Batch replace of hyperlinks in Word 2000

Posted on 2000-02-25
7
Medium Priority
?
827 Views
Last Modified: 2010-04-04
Ok, i have 500 differents .DOC files. Most of those files have hyperlinks in them. I would like to replace the HyperLink "http://www.this.com" named "THIS" by the HyperLink "http://www.that.com" (I don't care about the name of the hyperlink)

Is there a way to do this WITHOUT opening each of the .DOC files to verify if the link is in it and then change it manually...

Excuse my english and... Thanks !
0
Comment
Question by:ouaouaron
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Expert Comment

by:dovcamp
ID: 2560431
Here's a quick and dirty way, it's not perfect, but it should work.  First do a batch conversion of all files to .rtf format (this should preserve the majority of formating, but some newer features could be lost) using Word 2000's Batch Conversion Wizard.  Then use any batch search and replace utility to replace the hyperlinks that you mention above.  Several shareware batch search and replace programs can be found at http://winfiles.cnet.com/apps/98/text-search.html (choose your favorite).
Finally, convert all .RTF files back to .DOC files.
0
 
LVL 17

Expert Comment

by:calacuccia
ID: 2560883
Hi ouaouaron,

this little sub will check all documents in the path specified for the text "http://www.this.com", replace all matches by "http://www.that.com" and close the file, saved with the changes.

Supposing you don't have too much directories, that should do the job rather quickly, and you don't have to pass to .rtf files and formatting losses.

Sub Macro3()
    MyFile = Dir("C:\MyPath1\MyPath2\*.doc")
    While MyFile <> ""
    Documents.Open FileName:=MyFile
    With Selection.Find
        .Text = "http://www.this.com"
        .Replacement.Text = "http://www.that.com"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Documents(MyFile).Close SaveChanges:=wdSaveChanges
    MyFile = Dir
    Wend
End Sub

Hope this helps

Calacuccia
0
 
LVL 4

Expert Comment

by:Noggy
ID: 2562874
Heh, heh :-) , you'll never guess what: there is actually a http://www.this.com and a http://www.that.com - though you may find that you are forbidden to access the latter......


.....there is also a http://www.thisnthat.com AND a http://www.thisandthat.com.

PS Sorry about the tangent, ouaouaron.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:ouaouaron
ID: 2565559
Thanks for putting a smile in my face on a monday morning Noggy... That's something.. :)

I can't use Dovcamp's solution because of the complexity of my .doc files...


Calacuccia, your solution would work fine if i had to replace the name of the link. But it's the link itself that i have to change and a find methode will not find it.

But i think i've work it out this morning...:

Sub pp_ReplaceHyperLinks()


 MyFile = Dir("C:\*.doc", 16)
 
 While MyFile <> ""
   
    Documents.Open "C:\" & MyFile
   
    For Each hLink In ActiveDocument.Hyperlinks
   
        If InStr(hLink.Address, "this.com") <> 0 Then
            hLink.Address = "www.that.com"
        End If
       
    Next hLink

    ActiveDocument.Save
    ActiveDocument.Close
   
    MyFile = Dir
   
 Wend
 
 End Sub


0
 
LVL 17

Accepted Solution

by:
calacuccia earned 600 total points
ID: 2566887
Hi Ouaouaron,

the macro you typed is indeed a big step in the good direction. Forgive me for not having very well interpreted your question the first time and mixing up the naes with the actual hyperlinks.

The code I will post below will work to remove hyperlinks corresponding to what you specify and create a new one following your specification on the same place without changing the "Name".
It has to be done that way, because the Hyperlink.Address property is read-only and can not be modified by VBA once it exists, so the only method is to remove old hyperlink, and add a new one.

For the moment, I've taken my own Dir loop through one directory, as yours will not work. By using the ,16) at the end of your first dir call, you indeed look for subdirectories, but all you will get are their names, the macro won't loop through it.

So for the moment, as a first step, consider this, while I continue to look for a loop through all subdirectories, as that seems what you're looking for.

Sub pp_ReplaceHyperLinks()
 MyPath = "C:\MyPath1\MyPath2\"
 MyFile = Dir(MyPath & "*.doc")
    While MyFile <> ""
    Documents.Open FileName:=MyPath & MyFile
   
    For Each hlink In ActiveDocument.Hyperlinks
        If hlink.Address = "http://www.this.com/" Then
            hlink.Range.Select
            hlink.Delete
            ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
        "http://www.that.com/", SubAddress:=""
        End If
    Next hlink

    ActiveDocument.Save
    ActiveDocument.Close
     
    MyFile = Dir
     
 Wend
 
 End Sub

Calacuccia
0
 

Author Comment

by:ouaouaron
ID: 2569149
I calacuccia.

Thanks for the replay again...

I don't understand when you say that my macro won't work. I already used it to changed all my .doc files and it worked just well. The Hyperlinks.Address is R/W.

You are right about the (,16), it is useless... i realised it when i first tried my macro and that's why i had to had the path myself ("C:\"). But i forgot to remove the ,16....

You last comment made me realise that the 16 parameters is not for having the name of the file with it's current path but instead for conscidering folders in the loop...

(i'm french and i probably misunderstood the english description of the 16 parameter...)

Thanks for your time and bye !
0
 
LVL 17

Expert Comment

by:calacuccia
ID: 2569499
Hi Ouaouaron,

you're welcome.

Just to clear things up, I use Word 97 and in that previous version, the Hyperlinks.address is read-only, which explains my last comment/code modification. Just another reason to get Office 2000.

J'en profite pour te dire un petit bonjour en français, c'est assez rare ici de trouver des francophones. Moi-même, je suis belge, et de la partie flamande, mais comme j'ai habité Lille pendant 2 ans (où je travaillas), j'aime bien une p'tite conversation pour m'excercer un peu.

Salut,

Calacuccia
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question