Hi Steve
> Below finds the the first word on a line
> Question when found is it posiible to trim
> to 15 characters include spaces
I doubt whether this is all the code,
as this doesn't find the first word in a line only.
> an example could be "the cat won the show"
I'd say, there are 5 words.
hmm...
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
Steved - 22 Jul 2005 11:38 GMT
Hello Helmut
The macro's objective is to highliight a word for example
Seasons Greetings it would highlight Seasons off Seasons Greetings
Now I would like if possible a trim Function that would give me Seasons
Greetin
which is 15 characters in length including spaces.
is this possible if so how please.
Thanks.
> Hi Steve
>
[quoted text clipped - 15 lines]
> "red.sys" & chr(64) & "t-online.de"
> Word 2002, Windows 2000
Helmut Weber - 22 Jul 2005 12:42 GMT
Hi Steve,
to MS-Word "Seasons Greetings" are two words.
Whenever you introduce fuzzy natural language concepts
like "word", "syllable" or "sentence", you might find
yourself disappointed with what your code does.
Nevertheless, here comes another exercise.
Sub test8765()
ResetSearch ' clear search options
With Selection
.ExtendMode = False ' switch extendmode off, in case it is on
.StartOf unit:=wdStory ' goto start of doc
With .Find
.Text = "<[A-Za-z]@>"
.MatchWildcards = True
While .Execute
With Selection.Range
If Len(.Text) > 15 Then
.Text = Left(.Text, 15)
.Words(1).HighlightColorIndex = wdYellow
End If
Selection.MoveDown unit:=wdLine
Selection.StartOf unit:=wdLine
End With
Wend
End With
If IsLastline Then GoTo done ' thanks to Jonathan
End With
done:
ResetSearch
End Sub
' ---
Public Function IsLastline() As Boolean
' logic by Jonathan West
With ActiveDocument
IsLastline = (.Range.End - .Bookmarks("\Line").End) <= 1
End With
End Function
' ---
Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
' plus some more if needed
.Execute
End With
End Sub
Greetings from Bavaria, Germany
Helmut Weber, MVP, WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Steved - 22 Jul 2005 21:45 GMT
Thanks Helmut.
> Hi Steve,
>
[quoted text clipped - 64 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"