I'm having trouble getting a VB6 app to iterate the paragraphs in a Word
doc. It opens the doc fine , but every way I've tried to set an object to
Paragraphs is rejected. Migth someone be able to help?

Ed

Dim objWord As Object
Dim objFiles As Object
Dim objPar As Object
Dim rngPar As Object
Dim docFiles As String
Dim strFile As String
Dim strDest As String
Dim strHere As String

strDest = "C:\Documents and Settings\emillis\Desktop\XCopy\"

Set objWord = CreateObject("Word.Application")

docFiles = "C:\Documents and Settings\emillis\Desktop\XCopy\TestDoc.doc"
Set objFiles = objWord.Documents.Open(docFiles)

'Error here
Set objPar = objFiles.Paragraph

Re: Iterate paragraphs through VB6? by Cindy

Cindy
Thu Jun 24 13:44:51 CDT 2004

Hi Ed,

Your objFiles object would correspond to a Word.Document. And that doesn't
have a Paragraph property.

You'll find it helpful to declare object variables as Word. objects while
developing. If you need to use late-binding, change these to an Object
declaration once you're finished (except for the final testing, of course).

> Set objPar = objFiles.Paragraph

Set objPar = objFiles.RANGE.Paragraphs(1)

But from your title, I suspect what you're really looking for is

For each objpar in objFiles.Paragraphs

> I'm having trouble getting a VB6 app to iterate the paragraphs in a Word
> doc. It opens the doc fine , but every way I've tried to set an object to
> Paragraphs is rejected. Migth someone be able to help?
>
> Ed
>
> Dim objWord As Object
> Dim objFiles As Object
> Dim objPar As Object
> Dim rngPar As Object
> Dim docFiles As String
> Dim strFile As String
> Dim strDest As String
> Dim strHere As String
>
> strDest = "C:\Documents and Settings\emillis\Desktop\XCopy\"
>
> Set objWord = CreateObject("Word.Application")
>
> docFiles = "C:\Documents and Settings\emillis\Desktop\XCopy\TestDoc.doc"
> Set objFiles = objWord.Documents.Open(docFiles)
>
> 'Error here
> Set objPar = objFiles.Paragraph
>

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

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


Re: Iterate paragraphs through VB6? by Ed

Ed
Thu Jun 24 14:03:18 CDT 2004

Okay - I think the fog might be lifting a bit here . . .
"Cindy M -WordMVP-" <C.Meister-C@hispeed.ch> wrote in message
news:VA.00009c28.0124671a@speedy...
<<snip>>
> Your objFiles object would correspond to a Word.Document. And that doesn't
> have a Paragraph property.
>
> > Set objPar = objFiles.Paragraph
>
> Set objPar = objFiles.RANGE.Paragraphs(1)

Aha - if I *read* my book instead of look at it, I see the Paragraph
_property_ belongs to the Range and Selection objects. But the *Document*
object had a Paragraphs _collection_. And of course, these are not
interchangeable! 8>(

> But from your title, I suspect what you're really looking for is
>
> For each objpar in objFiles.Paragraphs

Yes, that's what I wanted. But, especially since I'm working in VB6 vs.
VBA, will the program know what "objPar" is, just by its association with
objFiles.Paragraphs? I thought I would need to Set it before I used it. If
I use Set objPar = objFiles.RANGE.Paragraphs(1), wouldn't I have to use (i),
and do a Paragraphs.Count?

> You'll find it helpful to declare object variables as Word. objects while
> developing. If you need to use late-binding, change these to an Object
> declaration once you're finished (except for the final testing, of
course).

I tried the early binding. But every Word.(object) declaration (.Document,
.Paragraph) was rejected. So I said, "Okay - you're all objects!" At least
that way, I could get *something* done! 8>\

Ed



Re: Iterate paragraphs through VB6? by Chad

Chad
Thu Jun 24 15:17:03 CDT 2004

The program will know that objPar is a Paragraph object because the
For...Each construct iterates through the members of a collection, and the
members of the objFiles.Paragraphs collection are Paragraph objects.

Regards,
Chad DeMeyer


"Ed" <Ed_Millis@NOSPAM.Hotmail.com> wrote in message
news:u5wfE2hWEHA.3512@TK2MSFTNGP12.phx.gbl...
> Okay - I think the fog might be lifting a bit here . . .
> "Cindy M -WordMVP-" <C.Meister-C@hispeed.ch> wrote in message
> news:VA.00009c28.0124671a@speedy...
> <<snip>>
> > Your objFiles object would correspond to a Word.Document. And that
doesn't
> > have a Paragraph property.
> >
> > > Set objPar = objFiles.Paragraph
> >
> > Set objPar = objFiles.RANGE.Paragraphs(1)
>
> Aha - if I *read* my book instead of look at it, I see the Paragraph
> _property_ belongs to the Range and Selection objects. But the *Document*
> object had a Paragraphs _collection_. And of course, these are not
> interchangeable! 8>(
>
> > But from your title, I suspect what you're really looking for is
> >
> > For each objpar in objFiles.Paragraphs
>
> Yes, that's what I wanted. But, especially since I'm working in VB6 vs.
> VBA, will the program know what "objPar" is, just by its association with
> objFiles.Paragraphs? I thought I would need to Set it before I used it.
If
> I use Set objPar = objFiles.RANGE.Paragraphs(1), wouldn't I have to use
(i),
> and do a Paragraphs.Count?
>
> > You'll find it helpful to declare object variables as Word. objects
while
> > developing. If you need to use late-binding, change these to an Object
> > declaration once you're finished (except for the final testing, of
> course).
>
> I tried the early binding. But every Word.(object) declaration
(.Document,
> .Paragraph) was rejected. So I said, "Okay - you're all objects!" At
least
> that way, I could get *something* done! 8>\
>
> Ed
>
>



Re: Iterate paragraphs through VB6? by Ed

Ed
Thu Jun 24 17:11:39 CDT 2004

Thanks for the boost, Chad.

Ed

"Chad DeMeyer" <don'tspamme@dude.net> wrote in message
news:esmD4giWEHA.808@tk2msftngp13.phx.gbl...
> The program will know that objPar is a Paragraph object because the
> For...Each construct iterates through the members of a collection, and the
> members of the objFiles.Paragraphs collection are Paragraph objects.
>
> Regards,
> Chad DeMeyer
>
>
> "Ed" <Ed_Millis@NOSPAM.Hotmail.com> wrote in message
> news:u5wfE2hWEHA.3512@TK2MSFTNGP12.phx.gbl...
> > Okay - I think the fog might be lifting a bit here . . .
> > "Cindy M -WordMVP-" <C.Meister-C@hispeed.ch> wrote in message
> > news:VA.00009c28.0124671a@speedy...
> > <<snip>>
> > > Your objFiles object would correspond to a Word.Document. And that
> doesn't
> > > have a Paragraph property.
> > >
> > > > Set objPar = objFiles.Paragraph
> > >
> > > Set objPar = objFiles.RANGE.Paragraphs(1)
> >
> > Aha - if I *read* my book instead of look at it, I see the Paragraph
> > _property_ belongs to the Range and Selection objects. But the
*Document*
> > object had a Paragraphs _collection_. And of course, these are not
> > interchangeable! 8>(
> >
> > > But from your title, I suspect what you're really looking for is
> > >
> > > For each objpar in objFiles.Paragraphs
> >
> > Yes, that's what I wanted. But, especially since I'm working in VB6 vs.
> > VBA, will the program know what "objPar" is, just by its association
with
> > objFiles.Paragraphs? I thought I would need to Set it before I used it.
> If
> > I use Set objPar = objFiles.RANGE.Paragraphs(1), wouldn't I have to use
> (i),
> > and do a Paragraphs.Count?
> >
> > > You'll find it helpful to declare object variables as Word. objects
> while
> > > developing. If you need to use late-binding, change these to an Object
> > > declaration once you're finished (except for the final testing, of
> > course).
> >
> > I tried the early binding. But every Word.(object) declaration
> (.Document,
> > .Paragraph) was rejected. So I said, "Okay - you're all objects!" At
> least
> > that way, I could get *something* done! 8>\
> >
> > Ed
> >
> >
>
>



Re: Iterate paragraphs through VB6? by Cindy

Cindy
Fri Jun 25 10:23:02 CDT 2004

Hi Ed,

> Aha - if I *read* my book instead of look at it,
>
<G>Getting one's head around Word's object model is a task and a half,
indeed.

> But, especially since I'm working in VB6 vs.
> VBA, will the program know what "objPar" is, just by its association with
> objFiles.Paragraphs? I thought I would need to Set it before I used it.
>
As Chad said :-) Plus, if you were using early-binding, it helps with the
speed in VB(a) being able to figure out what's meant.

> I tried the early binding. But every Word.(object) declaration (.Document,
> ..Paragraph) was rejected.
>
You'd need to set a REFERENCE in the project to the Word library. In VB, as I
recall, that's under Project/Properties.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

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