|
|
Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
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
|
|
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
"Bo Rasmussen" <krogenlund[ at ]hotmail.com> wrote in message news:emk6f3xKGHA.740[ at ]TK2MSFTNGP12.phx.gbl...
[Quoted Text] > 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 > > >
|
|
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
"Tony Jollans" <My Forename at My Surname dot com> wrote in message news:%236H%230GyKGHA.2828[ at ]TK2MSFTNGP12.phx.gbl...
[Quoted Text] > 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 > > > "Bo Rasmussen" <krogenlund[ at ]hotmail.com> wrote in message > news:emk6f3xKGHA.740[ at ]TK2MSFTNGP12.phx.gbl... > > 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 > > > > > > > >
|
|
Why not use something like Left$(oSection.Range.Text,4)
-- Enjoy, Tony
"Bo Rasmussen" <krogenlund[ at ]hotmail.com> wrote in message news:u$WIOQyKGHA.2304[ at ]TK2MSFTNGP15.phx.gbl...
[Quoted Text] > 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 > > > "Tony Jollans" <My Forename at My Surname dot com> wrote in message > news:%236H%230GyKGHA.2828[ at ]TK2MSFTNGP12.phx.gbl... > > 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 > > > > > > "Bo Rasmussen" <krogenlund[ at ]hotmail.com> wrote in message > > news:emk6f3xKGHA.740[ at ]TK2MSFTNGP12.phx.gbl... > > > 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 > > > > > > > > > > > > > > >
|
|
Thnx :o)
"Tony Jollans" <My Forename at My Surname dot com> wrote in message news:OXvNIXyKGHA.2036[ at ]TK2MSFTNGP14.phx.gbl...
[Quoted Text] > Why not use something like Left$(oSection.Range.Text,4) > > -- > Enjoy, > Tony > > > "Bo Rasmussen" <krogenlund[ at ]hotmail.com> wrote in message > news:u$WIOQyKGHA.2304[ at ]TK2MSFTNGP15.phx.gbl... > > 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 > > > > > > "Tony Jollans" <My Forename at My Surname dot com> wrote in message > > news:%236H%230GyKGHA.2828[ at ]TK2MSFTNGP12.phx.gbl... > > > 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 > > > > > > > > > "Bo Rasmussen" <krogenlund[ at ]hotmail.com> wrote in message > > > news:emk6f3xKGHA.740[ at ]TK2MSFTNGP12.phx.gbl... > > > > 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 > > > > > > > > > > > > > > > > > > > > > > > >
|
|
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
|
|
|