Where to place the Do

S

Steved

Hello from Steved

When I run the macro in "Step Mode" it works as it should.
There are 2 Paragraphs

The first Paragraph is to be boxed
The second paragraph is to replace dashes with nothing

My issue is when I got to run it, it only does the first only, Where should
the "Do" be placed please or is their another answer. Thanks


Sub Boxed()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Race"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.TypeText Text:=vbTab
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do
Selection.Find.Execute
If Selection.Find.Found Then
Selection.Find.ClearFormatting
With Selection.Find.Font
Selection.Font.Name = "Arial Black"
.Size = 18
.Bold = True
.Color = wdColorRed
End With
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection.Font
With .Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorLightYellow
End With
With .Borders(1)
.LineStyle = wdLineStyleDouble
.LineWidth = wdLineWidth150pt
.Color = wdColorAutomatic
End With
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleDouble
.DefaultBorderLineWidth = wdLineWidth150pt
.DefaultBorderColor = wdColorAutomatic
End With
Selection.Font.Color = wdColorRed
Selection.Font.Size = 18
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=" "
Selection.MoveDown Unit:=wdLine, Count:=3
End If
Loop While Selection.Find.Found
End Sub
 
K

Klaus Linke

Hi Steve,

Maybe explain what your text looks like and what you want to do?

Two things regarding your code:

-- Once you've found the word "Race", you don't need another search (for ^p)
to determine the paragraph.
You can access it directly -- Selection.Paragraphs(1)

-- "Selection.HomeKey Unit:=wdLine" is something you get from the macro
recorder. Usually you want to go to the start of the paragraph, not the
line.
And (see above) you can do so directly:
Selection.Paragraphs(1).Range.InsertBefore Text:=vbTab

-- Instead of applying lots of manual formatting for the foreground and
background colors, borders, font, size... rather define a paragraph style.

-- Then, you don't need any loop construct at all, but can simply replace
the word with the paragraph style (Replacement.Text being empty or "^&").

--If you really do need a loop construct, you'll probably find a lot of code
on these groups or elsewhere using "While Selection.Find.Execute ... Wend".
The thing to be aware of is that you need to put the selection after the
match you already handled (together with ".Wrap=wdFindStop" which you
already use) to avoid an endless loop.

Regards,
Klaus
 
S

Steved

Hello Klaus

1:25 RACE 3 - 9 Mar 2008 HOKI Overcast Slow 4.1 R70 $9000 1200 Ch
: 1
-------------------------------------------------------------------------------

ok put a border and font and background on the first paragraph
on the second paragraph remove the dashes

My attempt is below it is putting a border from RACE, I would like it to do
the whole paragaph and then do all the rest please Help Thankyou.

Sub Test()
Selection.Find.ClearFormatting
Selection.Find.Text = "Race"
Selection.HomeKey Unit:=wdLine
Selection.Find.Execute
Selection.Find.Text = "^p"
Selection.Extend
Selection.Find.Execute
With Selection.Find.Font
Selection.Font.Name = "Arial Black"
With Selection.Font
With .Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorLightYellow
End With
With .Borders(1)
.LineStyle = wdLineStyleDouble
.LineWidth = wdLineWidth150pt
.Color = wdColorBlue
End With
Selection.Font.Color = wdColorRed
Selection.Font.Size = 18
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=" "
Selection.MoveDown Unit:=wdLine, Count:=3
End With
End With
End Sub
 
K

Klaus Linke

Hi Steve,

I can only (mostly) repeat what I already said...

Define a paragraph style for what you want the "Race" paragraph to look like
(18 pt Arial Black, red, blue double border, yellow shading.

Then do a replacement:
Find what: Race
Replace with: ((leave this empty, but choose the style you just defined))

The macro recorder should give you the code (hopefully).

If you then want to delete the line with all the hyphens (----...), you
could do that with a wildcard replacement.
But if you don't know much about them, you can also achieve that with two
simple replacements:
Search for "-----" and replace with "Format > Paragraph > Alignment=Right".
Then Search for "Format > Paragraph > Alignment=Right" and replace with
nothing.

Again you can use the macro recorder. Since all replacements are "Replace
all", you don't need to muck with "Do" loops or something like that.

Regards,
Klaus
 
S

Steved

Hello Klaus

Thanks for your effort once again you have giving me something to go on with.
 

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