Macro - Table (text line delete & bold)

J

Josh O.

I need to create a macro to delete the first line of text in each cell in
column of a table and make the next line of text bold.

However my VBA skills are somewhat limited. Can anyone offer any help?
 
J

Jean-Guy Marcil

Josh O. said:
I need to create a macro to delete the first line of text in each cell in
column of a table and make the next line of text bold.

By line, do you mean paragraph (That ends with a ¶) or really "line" (Three
could be many lines in a paragraph)?
Do you need to check if the cells have text at all or not?
What if they have only one paragraph (line) to start with?
By "the next line of text ", you mean the paragraph (line) that is now the
first one once we have deleted the first paragraph (line), right?
 
J

Josh O.

I have solved my delete first line problem.

Yes, each cell in the table will have a least 2 paragraphs (ending with a ¶
carriage return). In the example below, text in the first cell of a table.
I need to have the "Main Street...Other" in bold, but not the Call to...etc.

Then in the next cell of the table (only 1 column of data), do the same
thing to the first line (paragraph).

Example:
Main Street Something or Other
Call to ....blah, blah, blah.
 
J

Jean-Guy Marcil

Josh O. said:
I have solved my delete first line problem.

Yes, each cell in the table will have a least 2 paragraphs (ending with a ¶
carriage return). In the example below, text in the first cell of a table.
I need to have the "Main Street...Other" in bold, but not the Call to...etc.

Then in the next cell of the table (only 1 column of data), do the same
thing to the first line (paragraph).

Example:
Main Street Something or Other
Call to ....blah, blah, blah.

The basic code would be something like this:

Dim rgeCell As Range
Dim i As Long

With ActiveDocument.Tables(1).Columns(1)
For i = 1 To .Cells.Count
Set rgeCell = .Cells(i).Range
With rgeCell
.Paragraphs(1).Range.Delete
.Paragraphs(1).Range.Font.Bold = True
End With
Next
End With

It works on the first table in the document and does not check for cell
content...
 
J

Josh O.

Jean-Guy Marcil said:
The basic code would be something like this:

Dim rgeCell As Range
Dim i As Long

With ActiveDocument.Tables(1).Columns(1)
For i = 1 To .Cells.Count
Set rgeCell = .Cells(i).Range
With rgeCell
.Paragraphs(1).Range.Delete
.Paragraphs(1).Range.Font.Bold = True
End With
Next
End With

It works on the first table in the document and does not check for cell
content...

Is there anyway to replace the text wrapping breaks with carriage returns (¶).
 
J

Josh O.

Ok. I figured out most of it so far.

Two things I need help with.
1. How can I replace only the first occurance of "^l" in each cell of the
column.

2. This code is inserting the paragraph break

Original Cell (formating marks):
Corn Hill ^l
1 or 2 BR, hrdwds, natural trim, coin-op laund in ^l
basement, off-st parking.

Cell after macro (formating marks):
Corn Hill ^p
^p
1 or 2 BR, hrdwds, natural trim, coin-op laund in ^p
basement, off-st parking.

What I want:
Corn Hill ^p
1 or 2 BR, hrdwds, natural trim, coin-op laund in ^l
basement, off-st parking.^p


Here is the code as I have it now:
Sub AddEnter()
Dim rgeCell As Range
Dim i As Long

With ActiveDocument.Tables(1).Columns(1)
For i = 1 To .Cells.Count
Set rgeCell = .Cells(i).Range
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^l"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With rgeCell
.Paragraphs(1).Range.InsertParagraphAfter
.ParagraphFormat.SpaceBefore = 0
.ParagraphFormat.SpaceAfter = 0
End With
Next
End With
End Sub
 
J

Josh O.

Jean-Guy Marcil said:
What are "text wrapping breaks"???

They do the same thing as a paragraph break, except distinguish a paragraph.
At the end of the line it looks like an arrow that goes down and then
90degrees left.

I am pasting a column of cells from Excel (03) to Word. Everywhere there is
an alt+enter in excel, it replaces it with text wrapping break. (the find
feature finds it as ^l). In word, Insert | Break | Text Wrapping break.
With the Show formating marks on, you can see it. (I figured this part out,
see my reply to myself).
 
J

Jean-Guy Marcil

Josh O. said:
They do the same thing as a paragraph break, except distinguish a paragraph.
At the end of the line it looks like an arrow that goes down and then
90degrees left.

I am pasting a column of cells from Excel (03) to Word. Everywhere there is
an alt+enter in excel, it replaces it with text wrapping break. (the find
feature finds it as ^l). In word, Insert | Break | Text Wrapping break.
With the Show formating marks on, you can see it. (I figured this part out,
see my reply to myself).

Ah... I have always called those "Manual Line Break," but I see that the
official name is indeed "Text Wrapping Break" (I never noticed that option on
the Insert Break dialog becasue I have always done SHIFT-Enter in order to
insert "Text Wrapping Breaks.")

Just do a regular Find/Replace operation where you Find "^l" and Replace
them with "^p".
 
J

Jean-Guy Marcil

Josh O. said:
Ok. I figured out most of it so far.

Two things I need help with.
1. How can I replace only the first occurance of "^l" in each cell of the
column.

2. This code is inserting the paragraph break

Original Cell (formating marks):
Corn Hill ^l
1 or 2 BR, hrdwds, natural trim, coin-op laund in ^l
basement, off-st parking.

Cell after macro (formating marks):
Corn Hill ^p
^p
1 or 2 BR, hrdwds, natural trim, coin-op laund in ^p
basement, off-st parking.

What I want:
Corn Hill ^p
1 or 2 BR, hrdwds, natural trim, coin-op laund in ^l
basement, off-st parking.^p

If I understood correctly, this should do what you want:


Sub AddEnter()

Dim rgeCell As Range
Dim i As Long

i = 1
With ActiveDocument.Tables(1).Columns(1)
For i = 1 To .Cells.Count
Set rgeCell = .Cells(i).Range
With rgeCell.Find
.Text = "^l"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceOne
End With
With rgeCell
.Paragraphs(1).Range.Font.Bold = True
End With
Next
End With

End Sub
 

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