This program requires a reference to the Word object model. Select Project/Add Reference. Click the COM tab and select "Microsoft Word 11.0 Object Library" (or whatever version you have on your system).
To remove the hyperlinks, the program opens a Word server and uses it to open the Word document. It loops over the document's stories. For each story, it loops through Hyperlinks collection, calling each one's Delete method.
A slightly odd thing happens in this code. The call to Open takes a parameter declared as an Object. If you try to pass in txtFile.Text, Visual Basic complains that it cannot convert an Object into a String. But wait. You're trying to do the opposite: pass a String in as an Object variable. That should work because a String is a type of Object (it inherits from Object).
The trick is that this parameter is declared without the ByVal keyword. That means it is passed by reference and the Open routine might change the Object's value. It cannot do that if you pass it a String instead of an Object so it complains. A bit backwards but it makes some sense.
|