Removing Spaces at the End

  • Follow


Below is a code where I allow 31 character max to get the full name of a 
person.  My question is this, how do I remove the extra spaces at the end 
before the text is placed in MS Word?

Thank you for your help!

' ********Code Begins  ****************

Dim FullName as String
Dim CASELEN as Long
Dim Testname as string
Dim Q as Integer

FullName = CurrentScreenObject.getstring(3, 33, 31)

CASELEN = Len(FullName)
        For Q = 1 To CASELEN
        Testname = Mid(FullName, Q, 1)
        If Testname = " " Then
            FullName = Left(FullName, Q - 1)
            Exit For
        End If
        Next Q

If FullName <> "" Then
                ActiveDocument.Bookmarks("NameBk").Select
                FullName = FullName & ""
                Selection.TypeText FullName & ""
          Else
            End If

0
Reply Utf 2/11/2010 4:10:01 PM

VBA has functions named RTrim(), LTrim(), and Trim() that remove white
space from the right end, the left end, and both ends of the string
passed to them as arguments, respectively.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.


On Thu, 11 Feb 2010 08:10:01 -0800, NFL
<NFL@discussions.microsoft.com> wrote:

>Below is a code where I allow 31 character max to get the full name of a 
>person.  My question is this, how do I remove the extra spaces at the end 
>before the text is placed in MS Word?
>
>Thank you for your help!
>
>' ********Code Begins  ****************
>
>Dim FullName as String
>Dim CASELEN as Long
>Dim Testname as string
>Dim Q as Integer
>
>FullName = CurrentScreenObject.getstring(3, 33, 31)
>
>CASELEN = Len(FullName)
>        For Q = 1 To CASELEN
>        Testname = Mid(FullName, Q, 1)
>        If Testname = " " Then
>            FullName = Left(FullName, Q - 1)
>            Exit For
>        End If
>        Next Q
>
>If FullName <> "" Then
>                ActiveDocument.Bookmarks("NameBk").Select
>                FullName = FullName & ""
>                Selection.TypeText FullName & ""
>          Else
>            End If
0
Reply Jay 2/11/2010 7:31:35 PM


Thank you so much!   That did the trick!

"Jay Freedman" wrote:

> 
> VBA has functions named RTrim(), LTrim(), and Trim() that remove white
> space from the right end, the left end, and both ends of the string
> passed to them as arguments, respectively.
> 
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP        FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the
> newsgroup so all may benefit.
> 
> 
> On Thu, 11 Feb 2010 08:10:01 -0800, NFL
> <NFL@discussions.microsoft.com> wrote:
> 
> >Below is a code where I allow 31 character max to get the full name of a 
> >person.  My question is this, how do I remove the extra spaces at the end 
> >before the text is placed in MS Word?
> >
> >Thank you for your help!
> >
> >' ********Code Begins  ****************
> >
> >Dim FullName as String
> >Dim CASELEN as Long
> >Dim Testname as string
> >Dim Q as Integer
> >
> >FullName = CurrentScreenObject.getstring(3, 33, 31)
> >
> >CASELEN = Len(FullName)
> >        For Q = 1 To CASELEN
> >        Testname = Mid(FullName, Q, 1)
> >        If Testname = " " Then
> >            FullName = Left(FullName, Q - 1)
> >            Exit For
> >        End If
> >        Next Q
> >
> >If FullName <> "" Then
> >                ActiveDocument.Bookmarks("NameBk").Select
> >                FullName = FullName & ""
> >                Selection.TypeText FullName & ""
> >          Else
> >            End If
> .
> 
0
Reply Utf 2/11/2010 8:37:01 PM

2 Replies
1005 Views

(page loaded in 0.052 seconds)

4/12/2014 10:53:29 AM


Reply: