question

SteveDee-5285 avatar image
0 Votes"
SteveDee-5285 asked SteveDee-5285 answered

vba to do a single page only

Hello from Steve

Is it possible please for vba to do a single page ie for example page 5.

Sub Hurdles()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Hdle"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Extend
With Selection.Find
.Text = ")"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection.Font
.Bold = True
.Color = 15773696
End With
Selection.EscapeKey
Selection.MoveDown Unit:=wdLine, Count:=1
End Sub

office-vba-devoffice-word-itpro
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@SteveDee-5285

As this issue is more related to VBA, I would add the related tag.
Thanks for your understandings.

0 Votes 0 ·

Hello emilyhua

I thank you.

All the best

Steve

0 Votes 0 ·
DougRobbins-0994 avatar image
1 Vote"
DougRobbins-0994 answered

Select the text on the page and then use the following modified code

Sub Hurdles()
Dim rng as Range
Set rng = Selection.Range
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Hdle"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Extend
With Selection.Find
.Text = ")"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Start >= rng.Start AND Selection.End<=rng.End
With Selection.Font
.Bold = True
.Color = 15773696
End With
End if
Selection.EscapeKey
Selection.MoveDown Unit:=wdLine, Count:=1
End Sub



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SteveDee-5285 avatar image
0 Votes"
SteveDee-5285 answered StefanBlom-6438 commented

Hello from Steve

The below is giving me a syntac error

If Selection.Start >= rng.Start AND Selection.End<=rng.End

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The line should end with "Then" (which is part of the If ... Then statement):

If Selection.Start >= rng.Start AND Selection.End<=rng.End Then

0 Votes 0 ·
SteveDee-5285 avatar image
0 Votes"
SteveDee-5285 answered

Hello StefanBlom

I thank you, Yes it now runs however is it possible to do the whole page please.

Meaning I have aleast 10 per page.

all the best Steve

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DougRobbins-0994 avatar image
1 Vote"
DougRobbins-0994 answered

Try:

Sub Hurdles()
Dim rng As Range, rngfound As Range
Set rng = Selection.Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="Hdle", MatchCase:=True, MatchWholeWord:=True, Forward:=True, MatchWildcards:=False, Wrap:=wdFindStop) = True
Set rngfound = Selection.Range
Selection.Collapse wdCollapseEnd
rngfound.End = rng.End
rngfound.End = rngfound.Start + InStr(rng, ")")
With rngfound
If .Start >= rng.Start Then
.Font.Bold = True
.Font.Color = 15773696
Else
Exit Sub
End If
End With
Loop
End With

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SteveDee-5285 avatar image
0 Votes"
SteveDee-5285 answered

Hello from Steve

I thank you Doug for the above.

I have tried it, however it is not Changing the .Font.Bold or Font.Colour.

It has in this script line "Selection.HomeKey wdStory" only.

Lets say for example I need to do only page 5.

I thank you for your time on this issue.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SteveDee-5285 avatar image
0 Votes"
SteveDee-5285 answered

Hello from Steve

I am sorry I forgot to highlight the particular page in this case page 5

It is Highlighting Hdle(0) Stpl(0)
8 JABELLA

We are nearly their All is required please is to Highlight Hdle(0) only

  1. 21481 LOGANS LOGIC All(14-2-2-0) $25,050 L(9-0-2) R(5-2-0) F(0) G(5-2-0) D(0) S(0) H(1-0-0) C(4-0-2) Dst(3-0-2) Hdle(0) Stpl(0)
    8 JABELLA

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.