Trying to search for the word "Totals"
which occurs towards the end of some tables,
and insert 3 rows above it, then underline two of the
newly inserted rows.

Can't seem to do it without mixing up the range
and causing an infinite loop.

Here's the code

For Each oTbl In objWord.ActiveDocument.Tables
Set oRg = oTbl.Range
With oRg.Find
.ClearFormatting
.Text = "Totals"
.Format = False
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = False
Do While .Execute
oRg.Rows(1).Range.Select
Selection.InsertRowsAbove 3
' range gets messed up, finds same "Total For" again and again.
Loop
End With
Next

Thanks
Jim

Insert Rows Above Found Text in Table by MSizlak

MSizlak
Tue Aug 03 13:31:40 CDT 2004

When you use range.find, the range gets reset to the
range of the found item. So add to your While . . . Wend
loop add the following line

oRg.end=oTbl.end

Moe
>-----Original Message-----
>Trying to search for the word "Totals"
>which occurs towards the end of some tables,
>and insert 3 rows above it, then underline two of the
>newly inserted rows.
>
>Can't seem to do it without mixing up the range
>and causing an infinite loop.
>
>Here's the code
>
> For Each oTbl In objWord.ActiveDocument.Tables
> Set oRg = oTbl.Range
> With oRg.Find
> .ClearFormatting
> .Text = "Totals"
> .Format = False
> .Forward = True
> .Wrap = wdFindStop
> .MatchWildcards = False
> Do While .Execute
> oRg.Rows(1).Range.Select
> Selection.InsertRowsAbove 3
> ' range gets messed up, finds same "Total
For" again and again.
> Loop
> End With
> Next
>
>Thanks
>Jim
>
>
>
>.
>

Re: Insert Rows Above Found Text in Table by James

James
Tue Aug 03 15:05:56 CDT 2004

Thanks, that's a good idea.

VBScript won't let me do
Set oRg.End = oTbl.Range.End
but there must be some variation thereof once you've invoked the appropriate
objects
and rerembered to use "Set".

Thanks Again
Jim

"MSizlak" <anonymous@discussions.microsoft.com> wrote in message
news:b7ef01c47988$1e4380b0$a301280a@phx.gbl...
> When you use range.find, the range gets reset to the
> range of the found item. So add to your While . . . Wend
> loop add the following line
>
> oRg.end=oTbl.end
>
> Moe
> >-----Original Message-----
> >Trying to search for the word "Totals"
> >which occurs towards the end of some tables,
> >and insert 3 rows above it, then underline two of the
> >newly inserted rows.
> >
> >Can't seem to do it without mixing up the range
> >and causing an infinite loop.
> >
> >Here's the code
> >
> > For Each oTbl In objWord.ActiveDocument.Tables
> > Set oRg = oTbl.Range
> > With oRg.Find
> > .ClearFormatting
> > .Text = "Totals"
> > .Format = False
> > .Forward = True
> > .Wrap = wdFindStop
> > .MatchWildcards = False
> > Do While .Execute
> > oRg.Rows(1).Range.Select
> > Selection.InsertRowsAbove 3
> > ' range gets messed up, finds same "Total
> For" again and again.
> > Loop
> > End With
> > Next
> >
> >Thanks
> >Jim
> >
> >
> >
> >.
> >



Re: Insert Rows Above Found Text in Table by Chad

Chad
Tue Aug 03 16:45:46 CDT 2004

James, instead of:

Do While .Execute
oRg.Rows(1).Range.Select
Selection.InsertRowsAbove 3
Loop

you could try:

.Execute
Do While .Found
oRg.Rows(1).Range.InsertRowsAbove 3
.Execute
.Execute
Loop

This method executes twice in each loop to go first to the instance you
already found, then search for another instance. It uses the .Found
property rather than the return value of .Execute to determine if another
instance was found.

Regards,
Chad


"James Pannozzi" <jpannozzi@csi.com> wrote in message
news:e5iSULYeEHA.3124@TK2MSFTNGP09.phx.gbl...
> Trying to search for the word "Totals"
> which occurs towards the end of some tables,
> and insert 3 rows above it, then underline two of the
> newly inserted rows.
>
> Can't seem to do it without mixing up the range
> and causing an infinite loop.
>
> Here's the code
>
> For Each oTbl In objWord.ActiveDocument.Tables
> Set oRg = oTbl.Range
> With oRg.Find
> .ClearFormatting
> .Text = "Totals"
> .Format = False
> .Forward = True
> .Wrap = wdFindStop
> .MatchWildcards = False
> Do While .Execute
> oRg.Rows(1).Range.Select
> Selection.InsertRowsAbove 3
> ' range gets messed up, finds same "Total For" again and
again.
> Loop
> End With
> Next
>
> Thanks
> Jim
>
>
>



Re: Insert Rows Above Found Text in Table by James

James
Wed Aug 04 10:41:26 CDT 2004

Thanks, that is a GREAT idea.

I'm building some reports in Word with VBScript
which I call from the main app which is written in C++.

Comming to VBA and VBScript from C++
there are a lot of conceptual similarities along
with some rather significant differences - sort of like
a person who has just mastered German suddenly trying
to say a few things in Dutch.


Thanks Again
Jim

"Chad DeMeyer" <cjdemeye at bechtel dot com> wrote in message
news:eMV98MaeEHA.2396@TK2MSFTNGP11.phx.gbl...
> James, instead of:
>
> Do While .Execute
> oRg.Rows(1).Range.Select
> Selection.InsertRowsAbove 3
> Loop
>
> you could try:
>
> .Execute
> Do While .Found
> oRg.Rows(1).Range.InsertRowsAbove 3
> .Execute
> .Execute
> Loop
>
> This method executes twice in each loop to go first to the instance you
> already found, then search for another instance. It uses the .Found
> property rather than the return value of .Execute to determine if another
> instance was found.
>
> Regards,
> Chad
>
>
> "James Pannozzi" <jpannozzi@csi.com> wrote in message
> news:e5iSULYeEHA.3124@TK2MSFTNGP09.phx.gbl...
> > Trying to search for the word "Totals"
> > which occurs towards the end of some tables,
> > and insert 3 rows above it, then underline two of the
> > newly inserted rows.
> >
> > Can't seem to do it without mixing up the range
> > and causing an infinite loop.
> >
> > Here's the code
> >
> > For Each oTbl In objWord.ActiveDocument.Tables
> > Set oRg = oTbl.Range
> > With oRg.Find
> > .ClearFormatting
> > .Text = "Totals"
> > .Format = False
> > .Forward = True
> > .Wrap = wdFindStop
> > .MatchWildcards = False
> > Do While .Execute
> > oRg.Rows(1).Range.Select
> > Selection.InsertRowsAbove 3
> > ' range gets messed up, finds same "Total For" again and
> again.
> > Loop
> > End With
> > Next
> >
> > Thanks
> > Jim
> >
> >
> >
>
>



Re: Insert Rows Above Found Text in Table by Chad

Chad
Wed Aug 04 10:53:55 CDT 2004

Glad I could help.

Regards,
Chad


"James Pannozzi" <jpannozzi@csi.com> wrote in message
news:epzXDmjeEHA.3984@TK2MSFTNGP10.phx.gbl...
> Thanks, that is a GREAT idea.
>
> I'm building some reports in Word with VBScript
> which I call from the main app which is written in C++.
>
> Comming to VBA and VBScript from C++
> there are a lot of conceptual similarities along
> with some rather significant differences - sort of like
> a person who has just mastered German suddenly trying
> to say a few things in Dutch.
>
>
> Thanks Again
> Jim
>
> "Chad DeMeyer" <cjdemeye at bechtel dot com> wrote in message
> news:eMV98MaeEHA.2396@TK2MSFTNGP11.phx.gbl...
> > James, instead of:
> >
> > Do While .Execute
> > oRg.Rows(1).Range.Select
> > Selection.InsertRowsAbove 3
> > Loop
> >
> > you could try:
> >
> > .Execute
> > Do While .Found
> > oRg.Rows(1).Range.InsertRowsAbove 3
> > .Execute
> > .Execute
> > Loop
> >
> > This method executes twice in each loop to go first to the instance you
> > already found, then search for another instance. It uses the .Found
> > property rather than the return value of .Execute to determine if
another
> > instance was found.
> >
> > Regards,
> > Chad
> >
> >
> > "James Pannozzi" <jpannozzi@csi.com> wrote in message
> > news:e5iSULYeEHA.3124@TK2MSFTNGP09.phx.gbl...
> > > Trying to search for the word "Totals"
> > > which occurs towards the end of some tables,
> > > and insert 3 rows above it, then underline two of the
> > > newly inserted rows.
> > >
> > > Can't seem to do it without mixing up the range
> > > and causing an infinite loop.
> > >
> > > Here's the code
> > >
> > > For Each oTbl In objWord.ActiveDocument.Tables
> > > Set oRg = oTbl.Range
> > > With oRg.Find
> > > .ClearFormatting
> > > .Text = "Totals"
> > > .Format = False
> > > .Forward = True
> > > .Wrap = wdFindStop
> > > .MatchWildcards = False
> > > Do While .Execute
> > > oRg.Rows(1).Range.Select
> > > Selection.InsertRowsAbove 3
> > > ' range gets messed up, finds same "Total For" again and
> > again.
> > > Loop
> > > End With
> > > Next
> > >
> > > Thanks
> > > Jim
> > >
> > >
> > >
> >
> >
>
>