Z
zSplash
So, long ago I was advised to use the Range object over the Selection
objection in many cases. Finally, I am able to spend a little time
re-writing my code with Range objects. (Perhaps this will solve many of my
issues, and make my code less sloppy.)
Suppose I have a cell in a table whose text I want to "juggle" (i.e., as I
easily do with the Selection object, in my old way of thinking -- move left,
insert text, move right, wdExtend, delete, bold, etc.). So, I've "captured"
the value of the cellRange object that I want to "tweak" with a string
variable. How can I easily remove the all characters in that string
variable whose Asc value = 7 (for example) that I don't want my string? (I
just used to make a loop and if the last character in the selection was
Asc=7, I'd delete it and go through the loop again until asc <> 7.) There
must be an easier (and less sloppy) way!
Here's what I've got, but it's not good, yet -- somehow, I keep adding more
Asc=7 characters to the range! Uff-dah:
Sub test()
Dim theText 'As String
Dim rngTable As Table, rngCell As Cell
Set rngTable = ActiveDocument.Range.Tables(1)
Set rngCell = rngTable.Cell(4, 2)
CheckItAgain:
If Asc(Right(rngCell, 1)) = 7 Then
theText = rngCell
theText = Left(theText, Len(theText) - 1)
rngCell.Range = theText
GoTo CheckItAgain
End If
End Sub
I hope this question makes sense.
TIA
objection in many cases. Finally, I am able to spend a little time
re-writing my code with Range objects. (Perhaps this will solve many of my
issues, and make my code less sloppy.)
Suppose I have a cell in a table whose text I want to "juggle" (i.e., as I
easily do with the Selection object, in my old way of thinking -- move left,
insert text, move right, wdExtend, delete, bold, etc.). So, I've "captured"
the value of the cellRange object that I want to "tweak" with a string
variable. How can I easily remove the all characters in that string
variable whose Asc value = 7 (for example) that I don't want my string? (I
just used to make a loop and if the last character in the selection was
Asc=7, I'd delete it and go through the loop again until asc <> 7.) There
must be an easier (and less sloppy) way!
Here's what I've got, but it's not good, yet -- somehow, I keep adding more
Asc=7 characters to the range! Uff-dah:
Sub test()
Dim theText 'As String
Dim rngTable As Table, rngCell As Cell
Set rngTable = ActiveDocument.Range.Tables(1)
Set rngCell = rngTable.Cell(4, 2)
CheckItAgain:
If Asc(Right(rngCell, 1)) = 7 Then
theText = rngCell
theText = Left(theText, Len(theText) - 1)
rngCell.Range = theText
GoTo CheckItAgain
End If
End Sub
I hope this question makes sense.
TIA