0
votes

Suppose I have a standard Word document called document.doc. Inside this document, there are hyperlinks to some server which no longer exists. I wish to replace the link with the aproper one, and since I must do this to many files, I hope there is a way to automate it.

How can I change the hyperlink to something else from outside Microsoft Office? Preferably in a Linux/Unix environment.

I noticed that all the hyperlinks in the document are stored in plaintext and can be viewed by

strings document.doc | grep -i "hyperlink"

I therefore tried a simple sed approach like this to edit in place:

sed -ir 's/www.badlink.com/www.goodlink.com/' document.doc

I then confirmed the hyperlink had changed by calling strings again. However, after using sed, the document cannot be opened by MS Word -- it states the file is corrupted.

So, is there any easy way to edit links in an Microsoft Word document by Linux/Unix tools? In the worst case, I imagine the task can be done with some Microsoft Office macro. And that is okay, too, if it is the only possibility.

1

1 Answers

1
votes

DOC is not RTF, you can't edit it with a simple text editor.

you can easily use VBA macro \ some other language using the word Interop libraries - to do this simple search&replace, for more information check

https://msdn.microsoft.com/en-us/library/f1f367bx.aspx

Now it depends on your needs, if you need to do this on the server side, you can always use OpenOffice or better yet Aspose (commercial licensed 3rd part libraries) to do these things (quite pricey but worth every penny - google them)

If you need to do this on the CLIENT side, and (assuming client uses word, means they are running Windows) you can do it using VBA macro \ Office addin.