Removing Spaces at the End

N

NFL

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
 
J

Jay Freedman

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
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
N

NFL

Thank you so much! That did the trick!

Jay Freedman said:
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
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.



.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top