
May 15th, 2008, 01:06 PM
|
 |
|
|
Join Date: Jun 2006
Location: Salem, OH
|
|
You'll need to begin by creating an instance of the Word automation object. Then, you can use that instance of Word to open your document, read the contents into a string variable, and close it again.
The code below should do the job for you very easily. You can simplify it quite a bit, but I've written it to allow for some different circumstances. I don't know what the formatting of your file looks like.
vb Code:
Original
- vb Code |
|
|
|
Const wdDoNotSaveChanges = 0 strDocument = "C:\mydoc.docx" 'Open Microsoft Word Set objWord = CreateObject("Word.Application") 'Keep it in a hidden window objWord.Visible = False 'Do not display file type warnings for older versions objWord.DisplayAlerts = False 'Open document in Read-only mode objWord.Documents.Open strDocument,, True 'Create a reference to the current document Set objDoc = objWord.ActiveDocument 'Remove any Word specific formatting Set objSelection = objWord.Selection objSelection.ClearFormatting 'Create a Range object of the file's contents Set objRange = objDoc.Content 'Is equivalent to: Set objRange = Range() 'Grab the text within that range strContents = objRange.Text 'Remove any non-printing characters such as bullets strContents = objWord.CleanString(strContents) 'Close Word without saving changes to the document objWord.Quit wdDoNotSaveChanges MsgBox strContents
__________________
 Click the image if at any point you don't like my decision.
Scripting problems? Windows questions? Ask the Windows Guru!
|