How to remova all pilcrons from cells of all tables?

A

avkokin

Hello.
There is many tables into doument. Some calls of these tables has
pilcrons (to end of text into cell). I need to remove it. How? I
started it so:

Sub TablesRemovePilcrows()
Dim oTab As Table
For Each oTab In ActiveDocument.Tables
??????
Next oTab
End Sub

Thank you.
 
H

Helmut Weber

Hi Anton,

how about that one:

Sub Test001()
Dim oTbl As Table
Dim oCll As Cell
For Each oTbl In ActiveDocument.Tables
For Each oCll In oTbl.Range.Cells
While oCll.Range.Characters.Last.Previous = Chr(13)
oCll.Range.Characters.Last.Previous = ""
Wend
Next
Next
End Sub
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
D

Doug Robbins - Word MVP

Use

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(Findtext:="^p", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop) = True
If Selection.Information(wdWithInTable) = True Then
Selection.Delete
End If
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

macropod

Hi avkokin,

Here's another approach:

Sub TablesRemovePilcrows()
Dim oTab As Table
For Each oTab In ActiveDocument.Tables
With oTab.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
Next oTab
End Sub
 
T

Tony Jollans

That would also remove paragraph marks elsewhere in the cell apart from at
the end (running multiple paragraphs together). As, indeed, would Doug's
proposal. Helmut's suggestion is closer to the mark but will fail if there
are any empty cells in any table.

This change to Helmut's code will, I believe, work as requested:

Sub Test001()
Dim oTbl As Table
Dim oCll As Cell
For Each oTbl In ActiveDocument.Tables
For Each oCll In oTbl.Range.Cells
Do While oCll.Range.Characters.Count > 1
If oCll.Range.Characters.Last.Previous = Chr(13) Then
oCll.Range.Characters.Last.Previous = ""
Else
Exit Do
End If
Loop
Next
Next
End Sub

--
Enjoy,
Tony

www.WordArticles.com

macropod said:
Hi avkokin,

Here's another approach:

Sub TablesRemovePilcrows()
Dim oTab As Table
For Each oTab In ActiveDocument.Tables
With oTab.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
Next oTab
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


avkokin said:
Hello.
There is many tables into doument. Some calls of these tables has
pilcrons (to end of text into cell). I need to remove it. How? I
started it so:

Sub TablesRemovePilcrows()
Dim oTab As Table
For Each oTab In ActiveDocument.Tables
??????
Next oTab
End Sub

Thank you.
 
D

Doug Robbins - Word MVP

The following modification of my code will remove just the last pilcrow from
a cell of the table

Dim frange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(Findtext:="^p", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop) = True
If Selection.Information(wdWithInTable) = True Then
If Selection.Range.End = Selection.Cells(1).Range.End - 1 Then
Selection.Delete
End If
End If
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Tony Jollans said:
That would also remove paragraph marks elsewhere in the cell apart from at
the end (running multiple paragraphs together). As, indeed, would Doug's
proposal. Helmut's suggestion is closer to the mark but will fail if there
are any empty cells in any table.

This change to Helmut's code will, I believe, work as requested:

Sub Test001()
Dim oTbl As Table
Dim oCll As Cell
For Each oTbl In ActiveDocument.Tables
For Each oCll In oTbl.Range.Cells
Do While oCll.Range.Characters.Count > 1
If oCll.Range.Characters.Last.Previous = Chr(13) Then
oCll.Range.Characters.Last.Previous = ""
Else
Exit Do
End If
Loop
Next
Next
End Sub

--
Enjoy,
Tony

www.WordArticles.com

macropod said:
Hi avkokin,

Here's another approach:

Sub TablesRemovePilcrows()
Dim oTab As Table
For Each oTab In ActiveDocument.Tables
With oTab.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
Next oTab
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


avkokin said:
Hello.
There is many tables into doument. Some calls of these tables has
pilcrons (to end of text into cell). I need to remove it. How? I
started it so:

Sub TablesRemovePilcrows()
Dim oTab As Table
For Each oTab In ActiveDocument.Tables
??????
Next oTab
End Sub

Thank you.
 
M

macropod

Hi Tony,

I understood from the subject description that all paragraph breaks were to be removed from the cells. The text of the OP's original
post didn't seem to explicitly contradict that.

--
Cheers
macropod
[MVP - Microsoft Word]


Tony Jollans said:
That would also remove paragraph marks elsewhere in the cell apart from at the end (running multiple paragraphs together). As,
indeed, would Doug's proposal. Helmut's suggestion is closer to the mark but will fail if there are any empty cells in any table.

This change to Helmut's code will, I believe, work as requested:

Sub Test001()
Dim oTbl As Table
Dim oCll As Cell
For Each oTbl In ActiveDocument.Tables
For Each oCll In oTbl.Range.Cells
Do While oCll.Range.Characters.Count > 1
If oCll.Range.Characters.Last.Previous = Chr(13) Then
oCll.Range.Characters.Last.Previous = ""
Else
Exit Do
End If
Loop
Next
Next
End Sub

--
Enjoy,
Tony

www.WordArticles.com

macropod said:
Hi avkokin,

Here's another approach:

Sub TablesRemovePilcrows()
Dim oTab As Table
For Each oTab In ActiveDocument.Tables
With oTab.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
Next oTab
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


avkokin said:
Hello.
There is many tables into doument. Some calls of these tables has
pilcrons (to end of text into cell). I need to remove it. How? I
started it so:

Sub TablesRemovePilcrows()
Dim oTab As Table
For Each oTab In ActiveDocument.Tables
??????
Next oTab
End Sub

Thank you.
 
H

Helmut Weber

Hi Tony,
Helmut's suggestion is closer to the mark
but will fail if there
are any empty cells in any table.

it seems, that only an empty first cell
will rise an error (91).

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
H

Helmut Weber

argh...

my attempt would also delete paragraph marks
preceding a table if the first cell is empty.

But with Tony's addition, everything seems to be alright.


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top