Parsing a Word doc and using data to create new doc

J

jbug_72

I want to programatically parse a Word document and create a new Word
document with the extracted data. I think creating a wizard/VB application
to do this would be ideal. As an alternative, I guess I could create a
macro. Does anyone have some VB code that I could look at?
 
T

Tony Jollans

You're not giving us much to go on here!

It depends what you want to be able to extract from your document but a
starting point is probably Word's Collections of Paragrahs, Sentences,
Words, and/or Characters, for example ..

Dim myWord As Range
For Each myWord In ActiveDocument.Words
Debug.Print myWord.Text
Next

(obviously doing your own thing instead of debug.print)
 
J

jbug_72

Sorry, I should've been more specific. The first thing I need to do is open
(i.e. have access to the words...not open for the user to see) an existing
Word document with Visual Basic. Do you know how to do this?
 
J

Jonathan West

This article will show you how to control Word from VB and open a document
by code.

Control Word from Excel
http://www.word.mvps.org/FAQs/InterDev/ControlWordFromXL.htm

Don't worry about the title - the principles & the code are pretty much
identical for VB6 and VBA. If you are using VB.NET you may have to adapt the
code somewhat as the language is different.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
T

Tony Jollans

You need to instantiate a Word object, and open your document within it ...

Dim appWord as Word.Application ' or Object for late binding
Dim docWord as Word.Document ' or Object for late binding

Set appWord = createobjetc("Word.Application")
Set docWord = appWord.Documents.Open "path and name of document"
:
' Do your stuff with the docWord document here
:
docWord.Close
appWord.Quit
Set docWord = Nothing
Set appWord = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top