Hi,

The following code is working perfectly for me except when it hits a table.
I would like it to SKIP tables and not put the sequential number field there.
I only want it if the paragraph style is Normal and not in a table.

Right now it is placing sequential numbers in each cell of the first table.
I'm getting the following error message when it gets to the end of the first
row:

Run-time error 5251. This is not a valid action for the end of a row.

I've tried several different options to get this to work. I've been looking
at it all day and am still not getting anywhere.

Any help would be greatly appreciated.

Thanks.

jbc
*********************************************
Dim oPar As Paragraph
Dim oRng As Range

ActiveWindow.View.ShowFieldCodes = True

For Each oPar In ActiveDocument.Paragraphs

If oPar.Style = "Normal" Then
If Not Mid(oPar.Range.Text, 3, 3) = "SEQ" Then

oPar.Range.InsertBefore vbTab
Set oRng = oPar.Range.Duplicate

oRng.Collapse direction:=wdCollapseStart
ActiveDocument.Fields.Add Range:=oRng, Type:=wdFieldSequence,
Text:= _
"Paragraph \# ""[0000]"" \n "

oRng.Paragraphs(1).Range.Fields(1).Result.Font.Bold = True

End If
End If

Next oPar

ActiveWindow.View.ShowFieldCodes = False
ActiveDocument.Fields.Update
*************************************************

Re: Loop thru doc problem by Jay

Jay
Wed Jul 20 21:01:56 CDT 2005

Replace the line

If oPar.Style = "Normal" Then

with

If (oPar.Style = "Normal") And _
(Not oPar.Range.Information(wdWithInTable)) Then

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

On Wed, 20 Jul 2005 15:27:05 -0700, jbc
<jbc@discussions.microsoft.com> wrote:

>Hi,
>
>The following code is working perfectly for me except when it hits a table.
>I would like it to SKIP tables and not put the sequential number field there.
> I only want it if the paragraph style is Normal and not in a table.
>
>Right now it is placing sequential numbers in each cell of the first table.
>I'm getting the following error message when it gets to the end of the first
>row:
>
>Run-time error 5251. This is not a valid action for the end of a row.
>
>I've tried several different options to get this to work. I've been looking
>at it all day and am still not getting anywhere.
>
>Any help would be greatly appreciated.
>
>Thanks.
>
>jbc
>*********************************************
>Dim oPar As Paragraph
>Dim oRng As Range
>
>ActiveWindow.View.ShowFieldCodes = True
>
>For Each oPar In ActiveDocument.Paragraphs
>
> If oPar.Style = "Normal" Then
> If Not Mid(oPar.Range.Text, 3, 3) = "SEQ" Then
>
> oPar.Range.InsertBefore vbTab
> Set oRng = oPar.Range.Duplicate
>
> oRng.Collapse direction:=wdCollapseStart
> ActiveDocument.Fields.Add Range:=oRng, Type:=wdFieldSequence,
>Text:= _
> "Paragraph \# ""[0000]"" \n "
>
> oRng.Paragraphs(1).Range.Fields(1).Result.Font.Bold = True
>
> End If
> End If
>
>Next oPar
>
>ActiveWindow.View.ShowFieldCodes = False
>ActiveDocument.Fields.Update
>*************************************************


Re: Loop thru doc problem by jbc

jbc
Thu Jul 21 07:12:02 CDT 2005

Jay,

Thank you so much. I tried something very similar, but did not use the ( ).
Why do you need them?

Thanks.

jbc

"Jay Freedman" wrote:

> Replace the line
>
> If oPar.Style = "Normal" Then
>
> with
>
> If (oPar.Style = "Normal") And _
> (Not oPar.Range.Information(wdWithInTable)) Then
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
>
> On Wed, 20 Jul 2005 15:27:05 -0700, jbc
> <jbc@discussions.microsoft.com> wrote:
>
> >Hi,
> >
> >The following code is working perfectly for me except when it hits a table.
> >I would like it to SKIP tables and not put the sequential number field there.
> > I only want it if the paragraph style is Normal and not in a table.
> >
> >Right now it is placing sequential numbers in each cell of the first table.
> >I'm getting the following error message when it gets to the end of the first
> >row:
> >
> >Run-time error 5251. This is not a valid action for the end of a row.
> >
> >I've tried several different options to get this to work. I've been looking
> >at it all day and am still not getting anywhere.
> >
> >Any help would be greatly appreciated.
> >
> >Thanks.
> >
> >jbc
> >*********************************************
> >Dim oPar As Paragraph
> >Dim oRng As Range
> >
> >ActiveWindow.View.ShowFieldCodes = True
> >
> >For Each oPar In ActiveDocument.Paragraphs
> >
> > If oPar.Style = "Normal" Then
> > If Not Mid(oPar.Range.Text, 3, 3) = "SEQ" Then
> >
> > oPar.Range.InsertBefore vbTab
> > Set oRng = oPar.Range.Duplicate
> >
> > oRng.Collapse direction:=wdCollapseStart
> > ActiveDocument.Fields.Add Range:=oRng, Type:=wdFieldSequence,
> >Text:= _
> > "Paragraph \# ""[0000]"" \n "
> >
> > oRng.Paragraphs(1).Range.Fields(1).Result.Font.Bold = True
> >
> > End If
> > End If
> >
> >Next oPar
> >
> >ActiveWindow.View.ShowFieldCodes = False
> >ActiveDocument.Fields.Update
> >*************************************************
>
>

Re: Loop thru doc problem by Jay

Jay
Thu Jul 21 11:48:19 CDT 2005

The VBA interpreter doesn't "need" the parentheses that separate the
arguments of the And operator unless the standard order of operator
evaluation would be different from the intended logic -- which it isn't, in
this case. But I need them to remind me of how to read the statement (slow
meatware!).

The parentheses around wdWithInTable are necessary because I want to use the
result of the Information function -- see
http://word.mvps.org/FAQs/MacrosVBA/BracketsWithArgmnts.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

jbc wrote:
> Jay,
>
> Thank you so much. I tried something very similar, but did not use
> the ( ). Why do you need them?
>
> Thanks.
>
> jbc
>
> "Jay Freedman" wrote:
>
>> Replace the line
>>
>> If oPar.Style = "Normal" Then
>>
>> with
>>
>> If (oPar.Style = "Normal") And _
>> (Not oPar.Range.Information(wdWithInTable)) Then
>>
>> --
>> Regards,
>> Jay Freedman
>> Microsoft Word MVP FAQ: http://word.mvps.org
>>
>> On Wed, 20 Jul 2005 15:27:05 -0700, jbc
>> <jbc@discussions.microsoft.com> wrote:
>>
>>> Hi,
>>>
>>> The following code is working perfectly for me except when it hits
>>> a table. I would like it to SKIP tables and not put the sequential
>>> number field there. I only want it if the paragraph style is Normal
>>> and not in a table.
>>>
>>> Right now it is placing sequential numbers in each cell of the
>>> first table. I'm getting the following error message when it gets
>>> to the end of the first row:
>>>
>>> Run-time error 5251. This is not a valid action for the end of a
>>> row.
>>>
>>> I've tried several different options to get this to work. I've
>>> been looking at it all day and am still not getting anywhere.
>>>
>>> Any help would be greatly appreciated.
>>>
>>> Thanks.
>>>
>>> jbc
>>> *********************************************
>>> Dim oPar As Paragraph
>>> Dim oRng As Range
>>>
>>> ActiveWindow.View.ShowFieldCodes = True
>>>
>>> For Each oPar In ActiveDocument.Paragraphs
>>>
>>> If oPar.Style = "Normal" Then
>>> If Not Mid(oPar.Range.Text, 3, 3) = "SEQ" Then
>>>
>>> oPar.Range.InsertBefore vbTab
>>> Set oRng = oPar.Range.Duplicate
>>>
>>> oRng.Collapse direction:=wdCollapseStart
>>> ActiveDocument.Fields.Add Range:=oRng,
>>> Type:=wdFieldSequence, Text:= _
>>> "Paragraph \# ""[0000]"" \n "
>>>
>>> oRng.Paragraphs(1).Range.Fields(1).Result.Font.Bold = True
>>>
>>> End If
>>> End If
>>>
>>> Next oPar
>>>
>>> ActiveWindow.View.ShowFieldCodes = False
>>> ActiveDocument.Fields.Update
>>> *************************************************