Trim Function

U

Umpty

I am walking down a table column looking for a specific string; during the
process, I encounter a character at the end of the string that resembles a
little square (forget what you call it). I try to use the Trim function, but
that does not remove it. The following is the code will hopefully help you
help me.

For i = 3 To TotRows
Dim TotLen As Integer, MyText As String, MyBkmrk As String
If strTableID = 9 Or strTableID = 12 Or strTableID = 14 Then
oApp.ActiveDocument.Tables(strTableID).Rows(i).Cells(2).Select
Else
oApp.ActiveDocument.Tables(strTableID).Rows(i).Cells(1).Select
End If
TotLen = Len(oApp.Selection.Text) - 2 (This line gets rid of most of the
little squares, but not in all cases. I know this is not the optimum way to
remove it.)
MyText = Trim(Left(oApp.Selection.Range, TotLen))
MyText = RTrim(MyText) (This line does not eradicate the little square"
MyBkmrk = strBkMrkPrefix & i
oApp.ActiveDocument.Close
oApp.Quit
OpenPicklistFile strTableID, MyText, MyBkmrk
Next i

If anyone could help, I would be most grateful.
Thanks
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Umpty > écrivait :
In this message said:
I am walking down a table column looking for a specific string; during the
process, I encounter a character at the end of the string that resembles a
little square (forget what you call it). I try to use the Trim function, but
that does not remove it. The following is the code will hopefully help you
help me.

For i = 3 To TotRows
Dim TotLen As Integer, MyText As String, MyBkmrk As String
If strTableID = 9 Or strTableID = 12 Or strTableID = 14 Then
oApp.ActiveDocument.Tables(strTableID).Rows(i).Cells(2).Select
Else
oApp.ActiveDocument.Tables(strTableID).Rows(i).Cells(1).Select
End If
TotLen = Len(oApp.Selection.Text) - 2 (This line gets rid of most of the
little squares, but not in all cases. I know this is not the optimum way to
remove it.)

This will remove the end of cell marker (the ¤ you can see in each cell when
Show All is on ¶).
MyText = Trim(Left(oApp.Selection.Range, TotLen))
MyText = RTrim(MyText) (This line does not eradicate the little
square"

RTrim is not necessary here because Trim does the same as LTrim and RTrim
together.

Trim removes spaces. The square you see must be a paragraph mark, i.e. there
was a paragraph mark before the end of cell marker.
You have to check for the last character after trimming it (Which might not
be necessary anymore if you were using Trim just to remove the ¶, if you
want to remove trailing spaces as well, then keep it, but apply it a second
time after having dealt with the last character in case there are now
trailing spaces at the end of the string after having removed the last ¶
from the string...)

'_______________________________________
Dim MyCell As Cell
Dim MyCellRange As Range
Dim CellText As String

Set MyCell = Selection.Cells(1)
Set MyCellRange = MyCell.Range

CellText = MyCellRange.Text
CellText = Left(CellText, Len(CellText) - 2)
If Asc(Mid(CellText, Len(CellText))) = 13 Then
CellText = Left(CellText, Len(CellText) - 1)
End If
'_______________________________________

But if you want to remove all ¶ from the string, then use something like
this instead,
(Note that this will not work with Word 97, if that is your case, write
back):

'_______________________________________
If Asc(Mid(CellText, Len(CellText))) = 13 Then
CellText = Replace(CellText, Chr(13), " ")
End If
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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