Ignore the Character

S

Steved

Hello from Steved

The below I would like to add to ignore X

12 PRIMO CANERA X8171 X2646

If the above did not have X my macro is fine how can I tell please to ignore X

Yes my objective is only to Highlite 12 PRIMO CANERA

Thankyou

Sub Highliter()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[0-9 ]{1,}[A-Z ]{1,}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[A-Z ]@>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
ActiveDocument.Save
Selection.Font.Color = wdColorRed
Options.DefaultHighlightColorIndex = wdYellow
Selection.Range.HighlightColorIndex = wdYellow
Selection.HomeKey Unit:=wdLine
End Sub
Sub RaceBegin()
WordBasic.PageSetupMargins Tab:=0, PaperSize:=1, TopMargin:="0.5", _
BottomMargin:="0", LeftMargin:="1.2", RightMargin:="0", Gutter:="0", _
PageWidth:="46.1", PageHeight:="23.3", Orientation:=1, FirstPage:=0, _
OtherPages:=0, VertAlign:=0, ApplyPropsTo:=4, FacingPages:=0, _
HeaderDistance:="0", FooterDistance:="0", SectionStart:=2, _
OddAndEvenPages:=0, DifferentFirstPage:=0, Endnotes:=0, LineNum:=0, _
CountBy:=0, TwoOnOne:=0, GutterPosition:=0, LayoutMode:=0,
DocFontName:= _
"", FirstPageOnLeft:=0, SectionType:=1, FolioPrint:=0,
ReverseFolio:=0, _
FolioPages:=1
Selection.WholeStory
Selection.Font.Size = 12
Selection.HomeKey Unit:=wdStory
ActiveDocument.SaveAs FileName:="Racebase.docx", FileFormat:= _
wdFormatXMLDocument, LockComments:=False, Password:="",
AddToRecentFiles _
:=True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveDocument.Close
Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0
End Sub
 
S

StevenM

To: Steved,

It would help if you would tell us a little more about what you are trying
to occomplish. For example, does:

12 PRIMO CANERA X8171 X2646

always appear on the same line? What are the other lines like?
 
S

StevenM

I accidentally hit "Post" without finishing my message.

The following macro looks for an X followed by digits and then another X
followed by digits. It then highlights the 3 words four words back.

If I knew more about your document, I might be able to come closer to what
you actually need.

Sub Highliter()
With Selection.Find
.ClearFormatting
.Text = "X[0-9]{1,} X[0-9]{1,}"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
.Execute
End With
If Selection.Find.Found = True Then
Selection.MoveLeft wdWord, 4
Selection.MoveRight wdWord, 3, Extend:=True
'ActiveDocument.Save
Selection.Font.Color = wdColorRed
Options.DefaultHighlightColorIndex = wdYellow
Selection.Range.HighlightColorIndex = wdYellow
Selection.HomeKey Unit:=wdLine
End If
End Sub

Steven Craig Miller
 
S

Steved

Hello StevenM

Please excuse my igorance, you are completly correct, I should firstly read
what I require, meaning it tells what is required.

Yes it is only on one line and I should have said only find the Character
"X" at the beginnining

12 PRIMO CANERA X8171 X2646

ie 12 PRIMO CANERA X

Now highlite "12 PRIMO CANERA" only

Thanks for taking timeout

Steved
 
T

Tony Jollans

Steve,

I'm sorry to say we are not mind readers and do not have access to your
data, nor knowledge of what you want to achieve. It's all, probably,
straightforward but the required Find pattern(s) depend on knowing all
possibilities, so ...

If you have 12 PRIMO CANERO X1234 ...
you want to highlight 12 PRIMO CANERO

What if you have 12 PRIMO CANERO 1234?

What if you have 12 PRIMO XANERO 1234?

What if you have X1234?

What if you have X1234 12 PRIMO CANERO?

etc., etc.

--
Enjoy,
Tony

Steved said:
Hello StevenM

Please excuse my igorance, you are completly correct, I should firstly
read
what I require, meaning it tells what is required.

Yes it is only on one line and I should have said only find the Character
"X" at the beginnining

12 PRIMO CANERA X8171 X2646

ie 12 PRIMO CANERA X

Now highlite "12 PRIMO CANERA" only

Thanks for taking timeout

Steved



StevenM said:
I accidentally hit "Post" without finishing my message.

The following macro looks for an X followed by digits and then another X
followed by digits. It then highlights the 3 words four words back.

If I knew more about your document, I might be able to come closer to
what
you actually need.

Sub Highliter()
With Selection.Find
.ClearFormatting
.Text = "X[0-9]{1,} X[0-9]{1,}"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
.Execute
End With
If Selection.Find.Found = True Then
Selection.MoveLeft wdWord, 4
Selection.MoveRight wdWord, 3, Extend:=True
'ActiveDocument.Save
Selection.Font.Color = wdColorRed
Options.DefaultHighlightColorIndex = wdYellow
Selection.Range.HighlightColorIndex = wdYellow
Selection.HomeKey Unit:=wdLine
End If
End Sub

Steven Craig Miller
 
S

Steved

Hello Tony

Yes a good point, I know what I require but if I do not explain, nobody is
going to understand which is a fair point.

My objective is to ask the macro to Stop at the first X after the last
Character
for example the macro I have at the moment highlites 2 PRIMO and 12 PRIMO
CANERO now if it finds an X as for example it will highlite 2 PRIMO X1234 and
12 PRIMO CANERO X1234 which is not what I want.

Yes it is one Paragraph on the same line.
So if the macro finds an X after the last Character and Space I need the
macro to stop and go back and highlite only 12 PRIMO CANERO not 12 PRIMO
CANERO 1234 and 12 PRIMO CANERO X1234.

Hopefully I've explaine a little more clearly

I thankyou

Steved










Tony Jollans said:
Steve,

I'm sorry to say we are not mind readers and do not have access to your
data, nor knowledge of what you want to achieve. It's all, probably,
straightforward but the required Find pattern(s) depend on knowing all
possibilities, so ...

If you have 12 PRIMO CANERO X1234 ...
you want to highlight 12 PRIMO CANERO

What if you have 12 PRIMO CANERO 1234?

What if you have 12 PRIMO XANERO 1234?

What if you have X1234?

What if you have X1234 12 PRIMO CANERO?

etc., etc.

--
Enjoy,
Tony

Steved said:
Hello StevenM

Please excuse my igorance, you are completly correct, I should firstly
read
what I require, meaning it tells what is required.

Yes it is only on one line and I should have said only find the Character
"X" at the beginnining

12 PRIMO CANERA X8171 X2646

ie 12 PRIMO CANERA X

Now highlite "12 PRIMO CANERA" only

Thanks for taking timeout

Steved



StevenM said:
I accidentally hit "Post" without finishing my message.

The following macro looks for an X followed by digits and then another X
followed by digits. It then highlights the 3 words four words back.

If I knew more about your document, I might be able to come closer to
what
you actually need.

Sub Highliter()
With Selection.Find
.ClearFormatting
.Text = "X[0-9]{1,} X[0-9]{1,}"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
.Execute
End With
If Selection.Find.Found = True Then
Selection.MoveLeft wdWord, 4
Selection.MoveRight wdWord, 3, Extend:=True
'ActiveDocument.Save
Selection.Font.Color = wdColorRed
Options.DefaultHighlightColorIndex = wdYellow
Selection.Range.HighlightColorIndex = wdYellow
Selection.HomeKey Unit:=wdLine
End If
End Sub

Steven Craig Miller
 

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