Search here for all the info you want in this Blog

How to retrieve each word/character in a Word document

The following example uses Word object methods to retrieve and display each word or character in a Word file.

Example:
' Create an object reference to Microsoft Word. Open the specified .doc file.
Set WordApp = createobject("Word.Application")
Set WordObj = WordApp.Documents.Open ("c:\WordFile.doc", ,True)

' Display each word in the open document
For i = 1 to WordApp.ActiveDocument.Words.count
   msgbox WordApp.ActiveDocument.Words(i)
Next

' Display each character in the document
For j = 1 to WordApp.ActiveDocument.Characters.count
   msgbox WordApp.ActiveDocument.Characters(j)
Next

' msgbox WordApp.ActiveWindow.Selection.Text

' Close the file and release the Word object
WordObj.Close False
Set WordApp = Nothing

No comments:

Post a Comment