I need to insert the name of the paragraph style in front
of the text that is in the cells of all the tables in a
document.

This is how I did it for the regular text in a document:

Dim ParSty As String
ParSty = Selection.Paragraphs(1).Style
Selection.Range.InsertBefore "{" & ParSty & "}"
Do Until Selection.Paragraphs(1).Style = "END"
Selection.MoveDown Unit:=wdParagraph, Count:=1
ParSty = Selection.Paragraphs(1).Style
Selection.Range.InsertBefore "{" & ParSty & "}"
Loop

It works fine, but I'm not sure how to do the same thing
for tables. Can anyone help me?

Thanks.

Jerry

Re: Paragraph Styles for Text in All Cells by Gerald

Gerald
Thu Jul 03 14:34:56 CDT 2003

Doug:

I get a collection error on the 5th line, and a compile
error on the 6th line.

Any more help you can give would be appreciated.

Thanks.

Jerry

>-----Original Message-----
>Hi Gerald,
>
>Use
>
>Dim i As Integer, j As Integer, k As Integer
>For i = 1 To ActiveDocument.Tables.Count
> For j = 1 To activeDocuemnt.Tables(i).Rows.Count
> For k = 1 To ActiveDocument.Tables
(i).Columns.Count
> ActiveDocument.Tables(i).Cell(k,
j).Range.InsertBefore "{" &
>ActiveDocument.Tables(i).Cell(k, j).Range.Paragraphs
(1).Style & "}"
> Next k
> Next j
>Next i
>
>Please respond to the newsgroups for the benefit of
others who may be
>interested.
>
>Hope this helps
>Doug Robbins - Word MVP
>"Gerald Perna" <g.perna@elsevier.com> wrote in message
>news:05e101c340e6$95d8b950$a101280a@phx.gbl...
>> I need to insert the name of the paragraph style in
front
>> of the text that is in the cells of all the tables in a
>> document.
>>
>> This is how I did it for the regular text in a document:
>>
>> Dim ParSty As String
>> ParSty = Selection.Paragraphs(1).Style
>> Selection.Range.InsertBefore "{" & ParSty & "}"
>> Do Until Selection.Paragraphs(1).Style = "END"
>> Selection.MoveDown Unit:=wdParagraph, Count:=1
>> ParSty = Selection.Paragraphs(1).Style
>> Selection.Range.InsertBefore "{" & ParSty & "}"
>> Loop
>>
>> It works fine, but I'm not sure how to do the same thing
>> for tables. Can anyone help me?
>>
>> Thanks.
>>
>> Jerry
>
>
>.
>

Paragraph Styles for Text in All Cells by Denise

Denise
Thu Jul 03 17:21:51 CDT 2003

I tested the following code and it works like a charm,
although you might want to add a vbCr at the end of the
insertbefore text to set off the style name from the
original text. Don't forget to add your code to check for
the END style, or it will go one past the last cell and
tell you what that style is.

'Substitute the appropriate table number (i.e., Table 2 =
Tables(2).Range... in next statement

Set oTable = ActiveDocument.Range.Tables(1)

'For each cell in the table, (your explanation here)

For Each oCell In oTable.Range.Cells
oCell.Select
ParSty = Selection.Style
Selection.Range.InsertBefore "{" & ParSty & "}"
Next oCell

Good luck.

Denise

>-----Original Message-----
>I need to insert the name of the paragraph style in front
>of the text that is in the cells of all the tables in a
>document.
>
>This is how I did it for the regular text in a document:
>
>Dim ParSty As String
>ParSty = Selection.Paragraphs(1).Style
>Selection.Range.InsertBefore "{" & ParSty & "}"
>Do Until Selection.Paragraphs(1).Style = "END"
>Selection.MoveDown Unit:=wdParagraph, Count:=1
>ParSty = Selection.Paragraphs(1).Style
>Selection.Range.InsertBefore "{" & ParSty & "}"
>Loop
>
>It works fine, but I'm not sure how to do the same thing
>for tables. Can anyone help me?
>
>Thanks.
>
>Jerry
>.
>

Re: Paragraph Styles for Text in All Cells by Doug

Doug
Thu Jul 03 20:51:45 CDT 2003

Hi Gerald,

In addition, I had my j's and k's reversed.

Here is a corrected version (once again, the fifth line has wrapped:

Dim i As Integer, j As Integer, k As Integer
For i = 1 To ActiveDocument.Tables.Count
For j = 1 To ActiveDocument.Tables(i).Rows.Count
For k = 1 To ActiveDocument.Tables(i).Columns.Count
ActiveDocument.Tables(i).Cell(j, k).Range.InsertBefore "{" &
ActiveDocument.Tables(i).Cell(j, k).Range.Paragraphs(1).Style & "}"
Next k
Next j
Next i

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP
"Doug Robbins - Word MVP" <dkr@mvps.org> wrote in message
news:%23EHGREbQDHA.3664@tk2msftngp13.phx.gbl...
> Hi Gerald,
>
> The email program has wrapped the fifth line of code onto a second line
(the
> sixth). Place the cursor at the end of the fifth line and use the delete
> key to remove the line break.
>
> Please respond to the newsgroups for the benefit of others who may be
> interested.
>
> Hope this helps
> Doug Robbins - Word MVP
> "Gerald Perna" <g.perna@elsevier.com> wrote in message
> news:09ab01c3419a$2eb8fc30$a001280a@phx.gbl...
> > Doug:
> >
> > I get a collection error on the 5th line, and a compile
> > error on the 6th line.
> >
> > Any more help you can give would be appreciated.
> >
> > Thanks.
> >
> > Jerry
> >
> > >-----Original Message-----
> > >Hi Gerald,
> > >
> > >Use
> > >
> > >Dim i As Integer, j As Integer, k As Integer
> > >For i = 1 To ActiveDocument.Tables.Count
> > > For j = 1 To activeDocuemnt.Tables(i).Rows.Count
> > > For k = 1 To ActiveDocument.Tables
> > (i).Columns.Count
> > > ActiveDocument.Tables(i).Cell(k,
> > j).Range.InsertBefore "{" &
> > >ActiveDocument.Tables(i).Cell(k, j).Range.Paragraphs
> > (1).Style & "}"
> > > Next k
> > > Next j
> > >Next i
> > >
> > >Please respond to the newsgroups for the benefit of
> > others who may be
> > >interested.
> > >
> > >Hope this helps
> > >Doug Robbins - Word MVP
> > >"Gerald Perna" <g.perna@elsevier.com> wrote in message
> > >news:05e101c340e6$95d8b950$a101280a@phx.gbl...
> > >> I need to insert the name of the paragraph style in
> > front
> > >> of the text that is in the cells of all the tables in a
> > >> document.
> > >>
> > >> This is how I did it for the regular text in a document:
> > >>
> > >> Dim ParSty As String
> > >> ParSty = Selection.Paragraphs(1).Style
> > >> Selection.Range.InsertBefore "{" & ParSty & "}"
> > >> Do Until Selection.Paragraphs(1).Style = "END"
> > >> Selection.MoveDown Unit:=wdParagraph, Count:=1
> > >> ParSty = Selection.Paragraphs(1).Style
> > >> Selection.Range.InsertBefore "{" & ParSty & "}"
> > >> Loop
> > >>
> > >> It works fine, but I'm not sure how to do the same thing
> > >> for tables. Can anyone help me?
> > >>
> > >> Thanks.
> > >>
> > >> Jerry
> > >
> > >
> > >.
> > >
>
>



Re: Paragraph Styles for Text in All Cells by Doug

Doug
Thu Jul 03 20:53:06 CDT 2003

Hi Denise,

Take a large table say 20 x 20 and notice the difference in speed between
your code and the following

Dim i As Integer, j As Integer, k As Integer
For i = 1 To ActiveDocument.Tables.Count
For j = 1 To ActiveDocument.Tables(i).Rows.Count
For k = 1 To ActiveDocument.Tables(i).Columns.Count
ActiveDocument.Tables(i).Cell(j, k).Range.InsertBefore "{" &
ActiveDocument.Tables(i).Cell(j, k).Range.Paragraphs(1).Style & "}"
Next k
Next j
Next i

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP
"Denise Z" <dzivolich@cox.net> wrote in message
news:0b3701c341b1$809b63f0$a001280a@phx.gbl...
> I tested the following code and it works like a charm,
> although you might want to add a vbCr at the end of the
> insertbefore text to set off the style name from the
> original text. Don't forget to add your code to check for
> the END style, or it will go one past the last cell and
> tell you what that style is.
>
> 'Substitute the appropriate table number (i.e., Table 2 =
> Tables(2).Range... in next statement
>
> Set oTable = ActiveDocument.Range.Tables(1)
>
> 'For each cell in the table, (your explanation here)
>
> For Each oCell In oTable.Range.Cells
> oCell.Select
> ParSty = Selection.Style
> Selection.Range.InsertBefore "{" & ParSty & "}"
> Next oCell
>
> Good luck.
>
> Denise
>
> >-----Original Message-----
> >I need to insert the name of the paragraph style in front
> >of the text that is in the cells of all the tables in a
> >document.
> >
> >This is how I did it for the regular text in a document:
> >
> >Dim ParSty As String
> >ParSty = Selection.Paragraphs(1).Style
> >Selection.Range.InsertBefore "{" & ParSty & "}"
> >Do Until Selection.Paragraphs(1).Style = "END"
> >Selection.MoveDown Unit:=wdParagraph, Count:=1
> >ParSty = Selection.Paragraphs(1).Style
> >Selection.Range.InsertBefore "{" & ParSty & "}"
> >Loop
> >
> >It works fine, but I'm not sure how to do the same thing
> >for tables. Can anyone help me?
> >
> >Thanks.
> >
> >Jerry
> >.
> >



Paragraph Styles for Text in All Cells by Gerald

Gerald
Tue Jul 08 09:04:17 CDT 2003

Denise:

Thanks a lot.

Jerry

>-----Original Message-----
>I tested the following code and it works like a charm,
>although you might want to add a vbCr at the end of the
>insertbefore text to set off the style name from the
>original text. Don't forget to add your code to check
for
>the END style, or it will go one past the last cell and
>tell you what that style is.
>
>'Substitute the appropriate table number (i.e., Table 2 =
>Tables(2).Range... in next statement
>
>Set oTable = ActiveDocument.Range.Tables(1)
>
>'For each cell in the table, (your explanation here)
>
> For Each oCell In oTable.Range.Cells
> oCell.Select
> ParSty = Selection.Style
> Selection.Range.InsertBefore "{" & ParSty & "}"
> Next oCell
>
>Good luck.
>
>Denise
>
>>-----Original Message-----
>>I need to insert the name of the paragraph style in
front
>>of the text that is in the cells of all the tables in a
>>document.
>>
>>This is how I did it for the regular text in a document:
>>
>>Dim ParSty As String
>>ParSty = Selection.Paragraphs(1).Style
>>Selection.Range.InsertBefore "{" & ParSty & "}"
>>Do Until Selection.Paragraphs(1).Style = "END"
>>Selection.MoveDown Unit:=wdParagraph, Count:=1
>>ParSty = Selection.Paragraphs(1).Style
>>Selection.Range.InsertBefore "{" & ParSty & "}"
>>Loop
>>
>>It works fine, but I'm not sure how to do the same thing
>>for tables. Can anyone help me?
>>
>>Thanks.
>>
>>Jerry
>>.
>>
>.
>