|
|
Title | Remove hyperlinks from a Word file |
Description | This example shows how to remove hyperlinks from a Word file in Visual Basic 6. |
Keywords | Word, Microsoft Word, Microsoft Office, hyperlink |
Categories | Office, Miscellany |
|
|
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.
|
|
Private Sub cmdRemoveHyperlinks_Click()
Dim word_app As Word.Application
Dim word_doc As Word.Document
Dim doc_story As Word.Range
Dim hyper_link As Word.Hyperlink
' Make a Word server object.
Set word_app = New Word.Application
word_app.Visible = False
' Open the Document.
Set word_doc = word_app.Documents.Open(txtFile.Text)
' Loop over all document stories.
For Each doc_story In word_doc.StoryRanges
For Each hyper_link In doc_story.Hyperlinks
hyper_link.Delete
Next
Next doc_story
' Save and close the document.
word_doc.Close True
' Clean up.
word_app.Quit
MsgBox "Done"
End Sub
|
|
For more information on programming Word and other Microsoft Office applications with VBA, see my book Microsoft Office Programming: A Guide for Experienced Developers.
|
|
|
|
|
|