Is it possible to Trim a Selection.Text? 
Author Message
 Is it possible to Trim a Selection.Text?

Hi all,

I want to be able to trim my selections using Trim (LTrim/RTrim). Is it
possible to do that?

/Tommy



Wed, 13 Oct 2004 00:04:13 GMT  
 Is it possible to Trim a Selection.Text?

Quote:

> I want to be able to trim my selections using Trim (LTrim/RTrim).
> Is it possible to do that?

Hi Tommy,

I'm not quite sure what you want to do.
LTrim, RTrim and Trim are functions that you can use on Strings and
Variants.
You can use them without problems with Selection.Text:
    myString = Trim(Selection.Text)

Or do you want to change the Selection (object) so it doesn't contain
spaces at the start/end?

Sub LTrimSelection()
  Selection.MoveStartWhile Cset:=" ", Count:=wdForward
End Sub

Sub RTrimSelection()
  Selection.MoveEndWhile Cset:=" ", Count:=wdBackward
End Sub

Sub TrimSelection()
  Call LTrimSelection
  Call RTrimSelection
End Sub

Greetings, Klaus



Wed, 13 Oct 2004 07:23:45 GMT  
 Is it possible to Trim a Selection.Text?
(by e-mail)

Quote:
> Ok, thx! Looks great!

> But what if I want to trim the selection for tabs, newlines
> and linefeeds...  Not just " "...?

Hi Tommy,

If you want to remove tabs (vbTab), paragraph marks (vbCr) and manual
line breaks (Chr(11)), change
   Cset := " "
to
   Cset := " " & vbTab & vbCr & Chr(11)
in the macros.

You can look up "MoveStartWhile" in the Online help for more info.

Good luck,
Klaus

Quote:
> > I want to be able to trim my selections using Trim (LTrim/RTrim).
> > Is it possible to do that?

> Hi Tommy,

> I'm not quite sure what you want to do.
> LTrim, RTrim and Trim are functions that you can use on
> Strings and Variants.
> You can use them without problems with Selection.Text:
>     myString = Trim(Selection.Text)

> Or do you want to change the Selection (object) so it doesn't
> contain spaces at the start/end?

> Sub LTrimSelection()
>   Selection.MoveStartWhile Cset:=" ", Count:=wdForward
> End Sub

> Sub RTrimSelection()
>   Selection.MoveEndWhile Cset:=" ", Count:=wdBackward
> End Sub

> Sub TrimSelection()
>   Call LTrimSelection
>   Call RTrimSelection
> End Sub

> Greetings, Klaus



Sat, 16 Oct 2004 07:27:09 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to trim the current selection?

2. Difference between trim and trim$

3. Trim not trimming?

4. Trim() vs Trim$(), etc

5. Equivalent functionality to trim - but with a differenct character set trimmed

6. Trim vs Trim$

7. Trimming Text

8. Trimming text in RichTextBox?

9. Trimming text to use for input

10. treeview - leading spaces in text are trimmed

11. Is this possible, or am I pushing it?

12. Is this possible, or am I pushing it?

 

 
Powered by phpBB® Forum Software