Iterate paragraphs through VB6?

E

Ed

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
 
C

Cindy M -WordMVP-

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 :)
 
E

Ed

Okay - I think the fog might be lifting a bit here . . .
Your objFiles object would correspond to a Word.Document. And that doesn't
have a Paragraph property.


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
 
C

Chad DeMeyer

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
 
E

Ed

Thanks for the boost, Chad.

Ed

Chad DeMeyer said:
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
 
C

Cindy M -WordMVP-

Hi Ed,
Aha - if I *read* my book instead of look at it,
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 :)
 

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