Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Macro - Table (text line delete & bold)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Josh O. - 10 Mar 2008 21:12 GMT
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?
Jean-Guy Marcil - 11 Mar 2008 14:15 GMT
> 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?
Josh O. - 11 Mar 2008 18:41 GMT
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.

> > 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.
[quoted text clipped - 5 lines]
> 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?
Jean-Guy Marcil - 12 Mar 2008 14:02 GMT
> I have solved my delete first line problem.
>
[quoted text clipped - 8 lines]
> 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...
Josh O. - 12 Mar 2008 16:29 GMT
> > I have solved my delete first line problem.
> >
[quoted text clipped - 26 lines]
> 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 (¶).
Josh O. - 12 Mar 2008 17:56 GMT
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
Jean-Guy Marcil - 12 Mar 2008 20:05 GMT
> Ok.  I figured out most of it so far.
>
[quoted text clipped - 19 lines]
> 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
Jean-Guy Marcil - 12 Mar 2008 18:04 GMT
> ^

<snip>

> > 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 (¶).

What are "text wrapping breaks"???
Josh O. - 12 Mar 2008 18:43 GMT
> > ^
>
[quoted text clipped - 6 lines]
>
> 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).
Jean-Guy Marcil - 12 Mar 2008 19:52 GMT
> 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
[quoted text clipped - 5 lines]
> 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".

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.