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 / July 2005

Tip: Looking for answers? Try searching our database.

Trim to 15 Characters

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steved - 22 Jul 2005 08:26 GMT
Hello from Steved

Below finds the the first word on a line
Question when found is ti posiible to trim to 15 characters include spaces
in the below macro please.

an example could be "the cat won the show"
it would end up as "the cat won the"

   Selection.Find.ClearFormatting
   With Selection.Find
       .Text = "<[A-Za-z]@>"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindAsk
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchAllWordForms = False
       .MatchSoundsLike = False
       .MatchWildcards = True
   End With

Thankyou.
Helmut Weber - 22 Jul 2005 10:56 GMT
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"
 
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.