String Additon

A

Al & Cay Grant

Hey people,

I have the following line which takes data from a table and sets it to
strings;

ocsection = UserDetailsDoc.Tables(1).Cell(4, 2).Range
ocstation = UserDetailsDoc.Tables(1).Cell(5, 2).Range

Later on when I go
string1 = ocsection & ocstation
msgbox string1

I find that string 1 is actually

"section
?station

?"



I have checked the table and the extra lines are not coming from their.

Is it something to do with using range???



Whats the best solution? some sort of string cleanup?



Cheers



- Al
 
A

Al & Cay Grant

Found the solution to my own problem by a search on this group;

The Range command has the side effect of adding an extra vbCR.

I can clean this up by using code similar to;

sExample = Replace(ActiveDocument.Tables(1).Cell(3, 2).Range.Text, vbCr, "")

But is their a better command to use other than range which wont
pickup the extra vbCr?

- Al
 
M

Mark Tangard

Depends on what sort of twiddling you prefer most (or least...).
When I have to return a cell's content without the end-of-cell
character -- which, let's face it, is virtually all the time --
I use: [range].MoveEnd wdCharacter, -1 where [range] is a
variable set to the cell's range.

Also, there's a weird concept I've never quite gotten through:
The end-of-cell character is actually 2 characters. Except
when it isn't. Umm. I mean, there are occasions -- not ones
like what you describe, but there are times -- when you need
to clip off 2 characters instead of one. Sorry I can't think
of the specifics just now. If I could, I could probably make
a case for my method, substituting -2 of course, since you'd
need an even longer bunch of code the way your example does it.
 
H

Helmut Weber

Hi,
haven't seen so far an end-of-cell marker
consisting of just 1 character! Maybe my fault,
but don't think so. Very usually it should be
Chr$(13) & chr$(7). So you have to cut off
2 characters. And using selection in tables should
be one of the few cases, where selection is much
faster than range.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 
M

Mark Tangard

Hi Helmut,

I know it's *supposed* to be 2 characters, but then why
does this:

Dim r as Range
Set r = Selection.Cells(1).Range
r.MoveEnd wdCharacter, -1 ' <---- only 1, not 2

set the range to the cell content minus the ending
character(s)? This has always baffled me.
 
J

Jonathan West

Mark Tangard said:
Hi Helmut,

I know it's *supposed* to be 2 characters, but then why
does this:

Dim r as Range
Set r = Selection.Cells(1).Range
r.MoveEnd wdCharacter, -1 ' <---- only 1, not 2

set the range to the cell content minus the ending
character(s)? This has always baffled me.

That is because two ANSI characters (CR & LF) are represented on screen by a
single paragraph mark. So Word has a different idea of what a character is
compared to ANSI

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
 
M

Mark Tangard

Hm. OK, so VBA doesn't recognize the 2 characters when the
code needs to "back up" so as to exclude it/them? That makes
sense. But I'm pretty sure there *is* a situation where you
do need to count to 2 there, just can't remember what it is.
Do you? Maybe it's not a VBA scenario?
 
J

Jonathan West

Mark Tangard said:
Hm. OK, so VBA doesn't recognize the 2 characters when the
code needs to "back up" so as to exclude it/them? That makes
sense. But I'm pretty sure there *is* a situation where you
do need to count to 2 there, just can't remember what it is.
Do you? Maybe it's not a VBA scenario?

If you load the Text property into a string variable, the length of the
string as calculated using the Len function is different from the
..Characters.Count value when the selection or range includes a paragraph
mark. The Len function counts two ANSI characters, the Characters.Count
property just one.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
 

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