Discussion Locked

DOWNLOAD: Delete Word Document Hyperlinks VBScript

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Deleting a single hyperlink from a Word document is easy, but deleting 50 or 100 can be time consuming. Our Delete Word Document Hyperlinks VBScript quickly deletes all the hyperlinks from a Word document with just a few mouse clicks.

Check out the tool:
https://www.techrepublic.com.com/5138-10877-5715864.html

Then join this ongoing discussion and let us know if you find the Delete Word Document Hyperlinks VBScript useful and if there's anything we can do to improve the tool.

8 replies

by hoekbrwr

This will notwork.

look in sub Hyperlink(1).Delete should be
Hyperlink(i).Delete

Further on this is sloppy programming. Close your application Word on the same level as where created. So do not do this in the sub but in the main program!

by Bill Detwiler

Thank you for the feedback. Although I'm always open to constructive criticism, I must disagree with your statement that the script will not work as written. Other TechRepublic staff and I have tested the script and found it works properly. In fact, changing the script as you suggest caused an error message when I ran the script.

Does the script function when you run it?

As for sloppy programming, I acknowledge that this script is not perfect--but then little, if any code ever is. I am not a VB scripting guru, but I was able to quickly write a script that accomplishes what I believe is a useful task. I also openly called for comments and improvements.

I encourage you, and all TechRepublic members, to submit an improved version of this script. Send me a private message using a link on my profile page: https://www.techrepublic.com.com/5213-6257-0.html?id=3318195.

The message should outline your proposed improvements. I will evaluate your suggestions and determine whether they warrant updating the download. If they do, I'll publish a new version and of course provide you full credit for the suggested improvements.

by hoekbrwr

I have not tried your script, I have to confess. I do not use hyperlinks that much, so I have no stuff to try it on. Although at first glance I spotted that strange construction of your program.
May be I have to tell you that I am a hobby programmer as well and just only do it for exactly this kind of small helps as well. But sometimes you start a little bigger project and then you really have to know what you are doing and obide by the rules. Otherwise it will cost you your night rest searching for strange errors in your program. If you want to go further and also try to write bigger programs try to keep to the general rules you most probably will find somewhere on TechRepublic. Especially scope of variables, dimensioning them and open and closing of objects is a source of strange behaviour.

So for the general comment and now back to your prog. let me paste the loop with the delete:
For i = 0 To StartCount - 1
objDoc.Hyperlinks(i).Delete
Count = Count + 1
Next
I immediately spotted your 1(one) in the Hyperlinks object collection. I thought this should be i(india). Normally this should be in this kind of loop. However what happens..
Everytime you delete a hyperlink there will be one less. You just nibble of the first hyperlink everytime. It stops exactly when all hyperlinks are nibbled af the collection because you counted them in advance.
A better construction for this kind of task is the use of the For each loop like:
Dim hl as Hyperlink
For each hl in objDoc.Hyperlinks
hl.Delete
Next

So now i have to go on with my main tasks and hopefully this was useful for you.

by Bill Detwiler

I will admit that I tried using a "for each" loop in my original version, as that is a more efficient method. Unfortunately, the loop didn't work properly. When run it would only delete every other link. I therefore decided to use the less-efficient, but functional "for" loop.

I'll definitely test and consider your suggestion for the scripts next version--which will also include a file Browse feature.

by paulklerkx

Works Well except, when I run the script it appears to leave out a Backslash(\) .
E.G. If I run the script for a file called
C:\docs\http.doc
the new file that is created is called C:\docshttp_no_hyperlinks.doc
instead of
C:\docs\http_no_hyperlinks.doc

by davidbennett

I have a user that needs this kind of script in Excel, will this work, or can it be easily modified to work in Excel?

Thanks
David

by white owl

When you unzip this script file, do you put it in the Word folder or a sub folder? And will it show up in the Word menu bar?

And have you decided it's working just fine?

This would be very helpful to me!

by philaaa20

You can do the same in two keystrokes
CTRL-A (select all)
SHIFT-CTRL-F9 (unlink field)

So the code module is a long way to get to the same place! Although it is a nice example of a short utility to spur people into using VBA for word.

This discussion is closed to new replies.