Word Automation

B

Babu V.T

Hi,
I need to read all the headings(Heading1,Heading2 and
Heading3) of a MSword document and display them in a list
box.How can i acheive it using Visual basic 6.0(not VBA)
and word automation object
 
C

Cindy Meister -WordMVP-

Hi Babu,

Hmmm... I might try opening the document in OUTLINE view,
collapsing down to the levels you want, picking up
ActiveDocument.Range.Text and then use the SPLIT function to
put this in an array. Or you can loop through
ActiveDocument.Range.Paragraphs
I need to read all the headings(Heading1,Heading2 and
Heading3) of a MSword document and display them in a list
box.How can i acheive it using Visual basic 6.0(not VBA)
and word automation object

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep
30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 
J

Jezebel

It's a bit more than a code snippet you need, but the core of it will be
along these lines (assume you know how to create a reference to the document
from VB) ...

Dim pPar as Word.Paragraph

For each pPar in objWordDoc.Paragraphs
if left(pPar.Style, 7) = "Heading" then

[or if pPar.OutlineLevel < 10 then ]


....
end if
Next

One way to approach this if you're not sure how to start is to record a
macro in Word, then copy the VBA code across to VB. Roughly speaking, what
you do in VBA is done in VB as methods of the word application object.
 
C

Cindy Meister -WordMVP-

Hi Babu,
Can you pls give me the code snippet to do the below
functionality.
How about you open up Word and start by recording a macro
to get the basic syntax? As a VB6 programmer you surely
must know how to use For Each... Next to loop through a
collection. It really shouldn't be such a problem for you
to put it together, once you've been shown how it can work.

But if you get stuck on any particular part of the code, do
ask back, copying the code you have into your message, and
indicating where the problem is occurring.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

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