Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

Help Understanding Range Objects

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg - 01 Dec 2004 15:29 GMT
I recently worked with some code like this

Dim aWord As Range

For each aWord in ActiveDocument.Words

 Do something

Next aWord

Now I am trying to work with paragraphs.  I started with code like this:

Dim aParagraph As Range
For each aParagraph in ActiveDocument.Paragraphs

 Do something

Next aParagraph

With this code I am getting a RTE '13' Type mismatch.

What is causing this error?  Thanks.
Ed - 01 Dec 2004 15:56 GMT
The paragraph is an object, and is part of the Paragraphs collection.  Each
paragraph has a range that can be accessed, and objects within that range.
To work with a specific paragraph, try

Dim objPar As Paragraph

For Each objPar In ActiveDocument.Paragraphs
   MsgBox objPar.Range.Words(1)
Next objPar

HTH
Ed

> I recently worked with some code like this
>
[quoted text clipped - 18 lines]
>
> What is causing this error?  Thanks.
Greg - 01 Dec 2004 16:17 GMT
Ed,

Got it.  Thanks for the nudge.

> The paragraph is an object, and is part of the Paragraphs collection.  Each
> paragraph has a range that can be accessed, and objects within that range.
[quoted text clipped - 31 lines]
> >
> > What is causing this error?  Thanks.
Jonathan West - 01 Dec 2004 16:05 GMT
Hi Greg,

The Characters collection is a collection of objects in the document, each
of which is a Range object one character long

Similarly, the Words collection is a collection of Range objects each one
word long.

The Paragraphs collection is different, it is a collection of Paragrarph
objects. Each Paragraph object has a Range property which defines the text
of the paragraph. The reason that the paragaraphs collection is different is
that Paragraph objects have properties associated with the paragraph
formatting. You need to code like this

Dim aParagraph As Paragraph
For each aParagraph in ActiveDocument.Paragraphs

 With aParagraph.Range
   Do something
 End With

Next aParagraph

>I recently worked with some code like this
>
[quoted text clipped - 18 lines]
>
> What is causing this error?  Thanks.
Greg - 01 Dec 2004 17:33 GMT
Jonathan,

Thanks for the tips.  Was looking for a means to count bolded paragraphs in
a document.  I saw Ed's post earlier and put together the following:

Sub Test3()
Dim j As Long, objPar As Paragraph
j = 0
For Each objPar In ActiveDocument.Paragraphs
 If objPar.Range.Font.Bold = True Then j = j + 1
Next objPar
MsgBox "There are " & j & " bolded entries in this document"
End Sub

> Hi Greg,
>
[quoted text clipped - 41 lines]
> >
> > What is causing this error?  Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.