How to trim the current selection? 
Author Message
 How to trim the current selection?

What do you want? Do you want to remove all spaces from the string, or do
you just want to remove the spaces at the front and/or back?  I don't know
if this works in VBA, but it will in vb.

Front/back: Trim(mytext)

All spaces:

dim i as integer
dim strTemp as string
i = 0

do while i < len(mytext)
    if mid(mytext, i, 1) <> " " then
        strtemp = strtemp & mid(mytext, i, 1)
    end if
    i=i+1
loop

As I said I don't know if this works in VBA. I usually program in vb.

Toine van Deursen
Applidata b.v.


Here is what I have so far:
sub test()
   mytext = Selection.Text
   MsbBox mytext
end

Now what's the trick to get the spaces out of mytext?

Thanks for any tip
Thomas

If you know a solution to this problem, please submit it to
http://www.*-*-*.com/

+++++++++++ Posted via The-Codebook.Com, The Source for Developers
+++++++++++
http://www.*-*-*.com/ ;                    Java, VisualBasic,
VisualC++



Sun, 12 May 2002 03:00:00 GMT  
 How to trim the current selection?
Hi Thomas,

Do you want all the spaces out of your code or just the first and the last
char?
You can use Trim to remove the left,right, both spaces

example right out of help:

This example uses the LTrim function to strip leading spaces and the RTrim
function to strip trailing spaces from a string variable. It uses the Trim
function to strip both types of spaces.

Dim MyString, TrimString
MyString = "  <-Trim->  " ' Initialize string.
TrimString = LTrim(MyString) ' TrimString = "<-Trim->  ".
TrimString = RTrim(MyString) ' TrimString = "  <-Trim->".
TrimString = LTrim(RTrim(MyString)) ' TrimString = "<-Trim->".
' Using the Trim function alone achieves the same result.
TrimString = Trim(MyString) ' TrimString = "<-Trim->".

If you need te remove all the spaces use this code

 For bytpos = 1 To Len(Selection.Text) ' Replace all spaces with underscores
        If (Mid$(Selection.Text, bytpos, 1) = " ")  Then
            mytext= mytext& "_"
        Else
            mytext= mytext& Mid$(Selection.Text, bytpos, 1)
        End If

hope it works,
Pascal Piekar
www.avades.nl/users/ppiekar


Quote:
> Here is what I have so far:
> sub test()
>    mytext = Selection.Text
>    MsbBox mytext
> end

> Now what's the trick to get the spaces out of mytext?

> Thanks for any tip
> Thomas

> If you know a solution to this problem, please submit it to

http://www.the-codebook.com/show_code.asp?ProblemId=1210
Quote:

> +++++++++++ Posted via The-Codebook.Com, The Source for Developers
+++++++++++
> http://www.The-Codebook.com/                      Java, VisualBasic,

VisualC++


Sun, 12 May 2002 03:00:00 GMT  
 How to trim the current selection?
Killing all Spaces might also be done with

   s = Replace(s, " ", "")

It's shorter and probably much quicker.

Michael G. Schneider



Quote:
> What do you want? Do you want to remove all spaces from the string, or do
> you just want to remove the spaces at the front and/or back?  I don't know
> if this works in vba, but it will in vb.

> Front/back: Trim(mytext)

> All spaces:

> dim i as integer
> dim strTemp as string
> i = 0

> do while i < len(mytext)
>     if mid(mytext, i, 1) <> " " then
>         strtemp = strtemp & mid(mytext, i, 1)
>     end if
>     i=i+1
> loop

> As I said I don't know if this works in VBA. I usually program in vb.

> Toine van Deursen
> Applidata b.v.



> Here is what I have so far:
> sub test()
>    mytext = Selection.Text
>    MsbBox mytext
> end

> Now what's the trick to get the spaces out of mytext?

> Thanks for any tip
> Thomas

> If you know a solution to this problem, please submit it to
> http://www.the-codebook.com/show_code.asp?ProblemId=1210

> +++++++++++ Posted via The-Codebook.Com, The Source for Developers
> +++++++++++
> http://www.The-Codebook.com/                      Java, VisualBasic,
> VisualC++



Wed, 15 May 2002 03:00:00 GMT  
 How to trim the current selection?
Hi Michael, Ibby,

I hadn't stumbled across this function before but it indeed has been added
to Word 2K.

--
Bill Coan
Microsoft Word MVP
Neenah WI 54956 USA
http://www.wordmacros.com
. . .

Quote:

> Hi Michael,

> This method is available in Excel97 but not Word 97 VBA. I don't know
about
> Word2k.

> --
> Hope this helps.

> Please post any replies to the newsgroup so that others in the newsgroup
may
> contribute or benefit.



> | Killing all Spaces might also be done with
> |
> |    s = Replace(s, " ", "")
> |
> | It's shorter and probably much quicker.
> |
> | Michael G. Schneider

> |
> |
> |


> | > What do you want? Do you want to remove all spaces from the string, or
> do
> | > you just want to remove the spaces at the front and/or back?  I don't
> know
> | > if this works in vba, but it will in vb.
> | >
> | > Front/back: Trim(mytext)
> | >
> | > All spaces:
> | >
> | > dim i as integer
> | > dim strTemp as string
> | > i = 0
> | >
> | > do while i < len(mytext)
> | >     if mid(mytext, i, 1) <> " " then
> | >         strtemp = strtemp & mid(mytext, i, 1)
> | >     end if
> | >     i=i+1
> | > loop
> | >
> | > As I said I don't know if this works in VBA. I usually program in vb.
> | >
> | > Toine van Deursen
> | > Applidata b.v.
> | >


> | > Here is what I have so far:
> | > sub test()
> | >    mytext = Selection.Text
> | >    MsbBox mytext
> | > end
> | >
> | > Now what's the trick to get the spaces out of mytext?
> | >
> | > Thanks for any tip
> | > Thomas
> | >
> | > If you know a solution to this problem, please submit it to
> | > http://www.the-codebook.com/show_code.asp?ProblemId=1210
> | >
> | > +++++++++++ Posted via The-Codebook.Com, The Source for Developers
> | > +++++++++++
> | > http://www.The-Codebook.com/                      Java, VisualBasic,
> | > VisualC++
> | >
> | >
> |
> |



Wed, 15 May 2002 03:00:00 GMT  
 How to trim the current selection?
Oooops ...

I am a VB-programmer. Most of the time I assume, that anything in VB is also
in VBA. But it is good to hear, that VBA in Office 2000 now has come a step
closer to VB.

Michael G. Schneider



Quote:
> Hi Michael, Ibby,

> I hadn't stumbled across this function before but it indeed has been added
> to Word 2K.

> --
> Bill Coan
> Microsoft Word MVP
> Neenah WI 54956 USA
> http://www.wordmacros.com
> . . .



Quote:
> > Hi Michael,

> > This method is available in Excel97 but not Word 97 VBA. I don't know
> about
> > Word2k.

> > --
> > Hope this helps.

> > Please post any replies to the newsgroup so that others in the newsgroup
> may
> > contribute or benefit.



> > | Killing all Spaces might also be done with
> > |
> > |    s = Replace(s, " ", "")
> > |
> > | It's shorter and probably much quicker.
> > |
> > | Michael G. Schneider

> > |
> > |
> > |


> > | > What do you want? Do you want to remove all spaces from the string,
or
> > do
> > | > you just want to remove the spaces at the front and/or back?  I
don't
> > know
> > | > if this works in vba, but it will in vb.
> > | >
> > | > Front/back: Trim(mytext)
> > | >
> > | > All spaces:
> > | >
> > | > dim i as integer
> > | > dim strTemp as string
> > | > i = 0
> > | >
> > | > do while i < len(mytext)
> > | >     if mid(mytext, i, 1) <> " " then
> > | >         strtemp = strtemp & mid(mytext, i, 1)
> > | >     end if
> > | >     i=i+1
> > | > loop
> > | >
> > | > As I said I don't know if this works in VBA. I usually program in
vb.
> > | >
> > | > Toine van Deursen
> > | > Applidata b.v.
> > | >


> > | > Here is what I have so far:
> > | > sub test()
> > | >    mytext = Selection.Text
> > | >    MsbBox mytext
> > | > end
> > | >
> > | > Now what's the trick to get the spaces out of mytext?
> > | >
> > | > Thanks for any tip
> > | > Thomas
> > | >
> > | > If you know a solution to this problem, please submit it to
> > | > http://www.the-codebook.com/show_code.asp?ProblemId=1210
> > | >
> > | > +++++++++++ Posted via The-Codebook.Com, The Source for Developers
> > | > +++++++++++
> > | > http://www.The-Codebook.com/                      Java, VisualBasic,
> > | > VisualC++
> > | >
> > | >
> > |
> > |



Wed, 15 May 2002 03:00:00 GMT  
 How to trim the current selection?
Hi Michael,

This method is available in Excel97 but not Word 97 VBA. I don't know about
Word2k.

--
Hope this helps.

Please post any replies to the newsgroup so that others in the newsgroup may
contribute or benefit.



| Killing all Spaces might also be done with
|
|    s = Replace(s, " ", "")
|
| It's shorter and probably much quicker.
|
| Michael G. Schneider

|
|
|


| > What do you want? Do you want to remove all spaces from the string, or
do
| > you just want to remove the spaces at the front and/or back?  I don't
know
| > if this works in vba, but it will in vb.
| >
| > Front/back: Trim(mytext)
| >
| > All spaces:
| >
| > dim i as integer
| > dim strTemp as string
| > i = 0
| >
| > do while i < len(mytext)
| >     if mid(mytext, i, 1) <> " " then
| >         strtemp = strtemp & mid(mytext, i, 1)
| >     end if
| >     i=i+1
| > loop
| >
| > As I said I don't know if this works in VBA. I usually program in vb.
| >
| > Toine van Deursen
| > Applidata b.v.
| >


| > Here is what I have so far:
| > sub test()
| >    mytext = Selection.Text
| >    MsbBox mytext
| > end
| >
| > Now what's the trick to get the spaces out of mytext?
| >
| > Thanks for any tip
| > Thomas
| >
| > If you know a solution to this problem, please submit it to
| > http://www.the-codebook.com/show_code.asp?ProblemId=1210
| >
| > +++++++++++ Posted via The-Codebook.Com, The Source for Developers
| > +++++++++++
| > http://www.The-Codebook.com/                      Java, VisualBasic,
| > VisualC++
| >
| >
|
|



Thu, 16 May 2002 03:00:00 GMT  
 How to trim the current selection?
Hi Thomas and Pascal,
why so complicated? This single order works very fine. Enjoy.
Just select your text before.
Best regards
Christian
------------------------------------
Sub Spaces_away ()
WordBasic.EditReplace Find:=" ", Replace:="", Direction:=0,
MatchCase:=1, WholeWord:=1, PatternMatch:=0, SoundsLike:=0,
ReplaceAll:=1, Format:=0, Wrap:=wdFindStop
End Sub
------------------------------------------------------------------
Quote:
> -----Ursprngliche Nachricht-----

> Ver?ffentlicht um: Mittwoch, 24. November 1999 09:03
> Ver?ffentlicht in: beginners
> Unterhaltung: How to trim the current selection?
> Betreff: Re: How to trim the current selection?

> Hi Thomas,

> Do you want all the spaces out of your code or just the first
> and the last
> char?
> You can use Trim to remove the left,right, both spaces

> example right out of help:

> This example uses the LTrim function to strip leading spaces
> and the RTrim
> function to strip trailing spaces from a string variable. It
> uses the Trim
> function to strip both types of spaces.

> Dim MyString, TrimString
> MyString = "  <-Trim->  " ' Initialize string.
> TrimString = LTrim(MyString) ' TrimString = "<-Trim->  ".
> TrimString = RTrim(MyString) ' TrimString = "  <-Trim->".
> TrimString = LTrim(RTrim(MyString)) ' TrimString = "<-Trim->".
> ' Using the Trim function alone achieves the same result.
> TrimString = Trim(MyString) ' TrimString = "<-Trim->".

> If you need te remove all the spaces use this code

>  For bytpos = 1 To Len(Selection.Text) ' Replace all spaces
> with underscores
>         If (Mid$(Selection.Text, bytpos, 1) = " ")  Then
>             mytext= mytext& "_"
>         Else
>             mytext= mytext& Mid$(Selection.Text, bytpos, 1)
>         End If

> hope it works,
> Pascal Piekar
> www.avades.nl/users/ppiekar



> > Here is what I have so far:
> > sub test()
> >    mytext = Selection.Text
> >    MsbBox mytext
> > end

> > Now what's the trick to get the spaces out of mytext?

> > Thanks for any tip
> > Thomas

> > If you know a solution to this problem, please submit it to
> http://www.the-codebook.com/show_code.asp?ProblemId=1210

> > +++++++++++ Posted via The-Codebook.Com, The Source for Developers
> +++++++++++
> > http://www.The-Codebook.com/                      Java, VisualBasic,
> VisualC++



Tue, 28 May 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Is it possible to Trim a Selection.Text?

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. Getting the Current Time-Selection from Outlook 2002 Calendar

8. Macro To Insert Text at Current Selection

9. Column width at the current selection

10. Text column of current selection

11. Cr Rpts selection formula not current

12. DataGrid: maintaining current row selection when requerying underlying recordset

 

 
Powered by phpBB® Forum Software