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 / February 2006

Tip: Looking for answers? Try searching our database.

Extracting range from Section

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bo Rasmussen - 06 Feb 2006 13:04 GMT
Hi,

I have a document that contain a lot of sections. Each section starts with
an 4 characte identifier, which I would like to extract. Now I would like to
iterate through the sections, but receive a compiler error (wrong number of
arguments)

Dim oSection As Section
Dim oRange as Range

For Each oSection In ActiveDocument.Sections
   oRange = oSection.Range(0, 4) 'This is not accepted by compiler
   oRange = oSection.Range() 'This is accepted by compiler
Next oSection

'This is also OK
Set oRange = ActiveDocument.Range(0, 4)

What is the difference between the Range object returned by a Section and
that returned by ActiveDocument. And what should I actually iterate through
the sections?

Kind regards
Bo Rasmussen
Tony Jollans - 06 Feb 2006 13:31 GMT
Yes, it is a bit confusing, isn't it?

Document objects have a Range *method* which can (optionally) take a start
and end position to return a range which is a subset of the document range.

Other objects have a Range *property* which simply returns the complete
range belonging to the object.

I guess the underlying reason is to do with the fact that range starts and
ends are all measured relative to the document.

--
Enjoy,
Tony

> Hi,
>
[quoted text clipped - 20 lines]
> Kind regards
> Bo Rasmussen
Bo Rasmussen - 06 Feb 2006 13:48 GMT
Hi again,

Hmmm- do you know what I should do to obtain my goal then? I simply want to
iterate through the sections and retrieve the first 4 characters in each
section.

Kind regards
Bo Rasmussen

> Yes, it is a bit confusing, isn't it?
>
[quoted text clipped - 38 lines]
> > Kind regards
> > Bo Rasmussen
Tony Jollans - 06 Feb 2006 14:00 GMT
Why not use something like Left$(oSection.Range.Text,4)

--
Enjoy,
Tony

> Hi again,
>
[quoted text clipped - 51 lines]
> > > Kind regards
> > > Bo Rasmussen
Bo Rasmussen - 06 Feb 2006 14:10 GMT
Thnx :o)

> Why not use something like Left$(oSection.Range.Text,4)
>
[quoted text clipped - 61 lines]
> > > > Kind regards
> > > > Bo Rasmussen
Greg - 06 Feb 2006 16:28 GMT
Maybe:
Sub Test()
Dim oSection As Section
Dim oRange As Range

For Each oSection In ActiveDocument.Sections
 Set oRange = oSection.Range
 oRange.Collapse wdCollapseStart
 oRange.MoveEnd wdCharacter, 4
 MsgBox oRange
Next oSection

End Sub
 
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.