character code

K

Keith G Hicks

I'm trying to figure out the code for a rectangular block. I have some text
that comes out of an old DOS program. It's mostly text but there are a few
odd characters. I've handled most of them but one is a vertical rectangluar
block. This old DOS program exports the block into a text file as a Ý (Y
with an accent mark above it). I have a macro (vba code) that is converting
the Y into a pipe symbol but I'd rather convert it into the block that it's
supposed to be. If I open the DOS program, copy the text to the clipboard
and paste it directly into Word it does show the block. If I ALT+X the block
the code is 258C. But that doesn't work in my vba code.

Here's my code now:

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Ý"
.Replacement.Text = "|"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

How do I change the line .Replacement.Text = "|" so that I get the 258C
block. I tried figuring out the Chr() for it but had no success. I was going
to do this:

..Replacement.Text = Chr(<some decimal code>)

but I couldn't figure out the decimal code for it.

If you go here: http://en.wikipedia.org/wiki/Code_page_437, it says that
258C is 221 but Chr(221) didn't give me the rectangular block.
It just stays as a Ý

What am I doing wrong?

Keith
 
K

Keith G Hicks

Oooh, I discovered that this will insert the proper symbol for me:

Selection.InsertSymbol Font:="lucida console", CharacterNumber:=9612,
Unicode:=True

The above works for most regular text fonts (Arial, Courier, Times New
Roman, etc). So how do I implement that in a Find/Replace?
 
K

Keith G Hicks

Never mind. I got it. I realized I could put the rectangular block in a
find/replace window and record the macro. I got this:

..Replacement.Text = ChrW(9612)

Added that to my main code and all is well.
Thanks for reading.
:)
 
P

Pesach Shelniitz

Hi Keith,

All the characters that you referred to are related to ASCII 221. In Windows
Latin 1 (code page 1252) ASCII 221 is ? (Unicode DD). In a Command window,
holding the Alt key down and typing 221 produces the half-block ?(Unicode
2586) in accordance with the US-ASCII standard (code page 437), while
according to Western European ASCII (code page 850), ASCII 211 is the
vertical broken bar ¦ (Unicode A6). Now the connection between the three
characters that you mentioned might be a bit clearer.

To code any Unicode character in a macro, use ChrW. For example, in your
macro
change "|" to ChrW(&H258C) to replace the unwanted character by ?(Unicode
2586) .

Hope this helps,
Pesach Shelnitz
My Web site: http://makeofficework.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