special characters

S

SP

Question 1:

Sample characters: aAaòó

In VBA, how can I code to type these characters ?


I tried copy and paste, but what I got was: ???òó
Ex: Selection.TypeText Text:="???òó"

Question 2:
In Word, can I assign the above sample characters to one shortcut key?

Thanks
Steve
 
D

Doug Robbins

Use Chr(#) where # is the Ascii value of the chracaters.

For example

Selection.InsertBefore Chr(65)

will cause an A to be inserted.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

Anand.V.V.N

Hi,

What you could is is record a macro, and choose the keyboard option, assing
as shortcut key to it and type these characters and stop recording and when
press the shortcut key adn these characters would show up.

I assume you know to record a macro.

I hope this is what you were looking for and hope you found this helpful

Anand
 
C

Chuck

Not sure why aAa isn't copying and pasting for you, they're basic simple
characters and they do for me.

Most accented characters can be copied and pasted into the VBE either from
the character map or from a document. For characters that don't you'll need
the character code eg

Selection.InsertSymbol CharacterNumber:=8531, Unicode:=True

for the 1/3 symbol.

HTH

You can also use the ASCII value - look up "Asc Function" in VBE help.
 
S

SP

I tried the Chr( ), but an error says it is not a valid procedure.

Also, in my case, the # is 257, which is not ASCII.

Steve
 
S

SP

Yes, I followed this suggestion and it worked. Thanks

After assigning a shortcut key to a macro, is it possible to change it to a
different key ? I can't seem to find that anywhere.

Steve
 
S

SP

Selection.InsertSymbol Font:="Times New Roman", CharacterNumber:=257,
Unicode:=True

I found that the above worked for my case. When I pasted the character here
yesterday, it turned out, as you said, "aAa". Where in fact, it is the
character that the above code would generate.

Anyway, thanks for your help.
Steve


It's funny that the character I pasted here
 
A

Anand.V.V.N

Hi,
You can use chr$ and see if it works. And as for changing the shortcut
assignment what you can do it select the customize option from the Toolbars
in View menu, then choose Command Tab, and select keyboard.

I hope this helped you.

Anand
 
S

SP

Chr$( ) only works with code 255 or less. My character code is 257 and
therefore not working.

The only solution for me is to use
Selection.InsertSymbol Font:="Times New Roman", CharacterNumber:=257,
Unicode:=True

Also, thank you very much for the tip on re-assinging the shortcut key of a
macro. How that assignment managed to hide deep deep in
"View|Toolbars|Customize|Keyboard|Macros" is way beyond me. Thanks again
for pointing it out.

Steve
 
A

Anand.V.V.N

Hi,

You welcome. Thank you too on the tip, I didn't know about chr$() dosn'r
work beyond 255, actually didn't have to use it for characters beyond 255.

Anand
 
K

Klaus Linke

Since Word uses Unicode, it's almost always better to use ChrW() rather than Chr()/Chr$().
With that you can insert the characters into any string -- i.e. str = str & ChrW(257) -- and insert the whole text in one go, which will probably be a lot faster than using InsertSymbol each time.

Unfortunately, the VBA editor can't deal with Unicode directly. And unfortunately, it hasn't been updated the last versions, and probably never will (considering that MS works on retiring VBA).

Regards,
Klaus
 
S

SP

Now, that...is an improvement!! Thank you

Also, if VBA will be retired, what will replace VBA ?


Since Word uses Unicode, it's almost always better to use ChrW() rather than
Chr()/Chr$().
With that you can insert the characters into any string -- i.e. str = str &
ChrW(257) -- and insert the whole text in one go, which will probably be a
lot faster than using InsertSymbol each time.

Unfortunately, the VBA editor can't deal with Unicode directly. And
unfortunately, it hasn't been updated the last versions, and probably never
will (considering that MS works on retiring VBA).

Regards,
Klaus
 
K

Klaus Linke

Also, if VBA will be retired, what will replace VBA ?

No idea. But since VB has been abandoned for VB.Net, VBA's time seems to be running out, too.

Maybe I'm wrong and the next Word version will have an Unicode-enabled VBA editor. Since VBA will be with us for at least two more versions (as far as I heard), I'd definitely hope so.
It was just a (pessimistic) guess.

Greetings,
Klaus
 
S

SP

Let's see...

At the beginning, it started out with VB as the major league and VBA as the
minor league (sorta kinda).

Now, if VB.Net will be the major league, guess what will be the minor league
....VBA.Net, right ?

That would be so cool for a Microsoft transition.

Steve


Klaus Linke said:
Also, if VBA will be retired, what will replace VBA ?

No idea. But since VB has been abandoned for VB.Net, VBA's time seems to be
running out, too.

Maybe I'm wrong and the next Word version will have an Unicode-enabled VBA
editor. Since VBA will be with us for at least two more versions (as far as
I heard), I'd definitely hope so.
It was just a (pessimistic) guess.

Greetings,
Klaus
 

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