Search, Replace & Symbol, Decorative fonts

G

Guest

I am grappling with using the search / replace functionality in Word with
the so called decorative fonts. The object is to be able to create macros to
process sets of symbols from such fonts that are of interest to me.

The issue seems to be rather convoluted, and for starters I wanted to check
out what solutions might have been developed by others.

I found a couple of macros by Klaus Linke that based on their descriptions
could be useful. The macros are SymbolToUnicode and SymbolsUnprotect. The
url for them:
http://groups.google.com/group/micr...3d?q="SymbolToUnicode+replaces+any+character"

Unfortunately, neither of them works for me.

The problem might be that when I copy / paste from the browser the macros
code gets trashed due to incorrect browser codepage.

So if anyone (Klaus?) who used them and found them working, could share the
proper code with me either posting it here or e-mailing it to me, that would
be appreciated.

Pointers to any other pertinent information and code would also be
appreciated.

(I already read Finding and replacing symbols by Dave Rado.)

Sergey
 
C

Chand

Hi There

I got same problem while working with some unicode chars like ਿ ੠ੱ ੰ. Try
to search with use wildcard off and unicode charcode with ^uNNNN where n iin
unicode value i.e. ^u2562; as follows

Selection.Find.ClearFormatting
With Selection.Find
.text = "^u2562"
.Replacement.text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With
While Selection.Find.Execute

Its working perfectly but sometimes needs ^? at before or after the unicode
value to search combinations with any charater as ^? for any char; like
"^?^u2562^u" or "^?^?^u2526" etc.
 
G

Guest

Hello Chand,
I got same problem while working with some unicode chars like ? ? ? ?.
Try
to search with use wildcard off and unicode charcode with ^uNNNN where n
iin
unicode value i.e. ^u2562; as follows

Where do I get the unicode value?
Its working perfectly but sometimes needs ^? at before or after the
unicode
value to search combinations with any charater as ^? for any char; like
"^?^u2562^u" or "^?^?^u2526" etc.

When you search for ^?^uNNNN you are actually searching for two characters.

And as far as I understand, searching / replacing *unicode* characters is
simple and straightforward (when you have the unicode number of the
character). Also, when doing it programmatically the advice is to use
ChrW(NNN), as in

Selection.Find.ClearFormatting
With Selection.Find
.text = ChrW(2562)

Sergey
 
K

Klaus Linke

Hi Sergey,

The macros run fine if I copy/paste them from your link. I'm sending them in
an email anyway.

Maybe something else goes wrong?

If you run SymbolsUnprotect, you likely won't see any effect. That is ok.
Only in case you get an error message, something *is* wrong.
It's just turning "protected" symbols (which don't show the "Symbol" or
other decorative font in the font dropdown) into "unprotected" ones (which
do show the decorative font).
That's in preparation for the other macro.
If you check the commented-out section at the end of the macro, you can run
pretty similar code to (re-)protect the symbols.


For the other macro, SymbolToUnicode, you should select the text first (say
Ctrl+A if you want the macro to replace symbols from the Symbol font in the
whole doc) and then start the macro.

One problem I noticed when I checked the macros just now: Some of the
Unicode characters seem to be from a Unicode version newer than 2.0.
Therefore some characters may not exist in Arial Unicode MS on Windows XP
(or older).

I heard Windows Vista and Win7 have fonts that cover all the new characters
up to Unicode Version 5, so it may not be a problem there.

An example of a character that isn't in "Arial Unicode MS":
Case &HD2 ' # REGISTERED SIGN SERIF
myChar.Text = ChrW(&HF6DA)


Greetings from Stuttgart/Germany,
Klaus
 
G

Guest

Greetings to Stuttgart/Germany

Hello Klaus,

Thanks for your prompt and thorough reply.

I received your separate e-mail with the code as well.

Concerning the SymbolToUnicode macro, I did not know about selecting symbols
before running the macro. That bit of information applied, the code I copied
from the Google page works fine. And this macro can be useful in its own
right.

As mentioned before, I'd like to be able to produce my own custom macros.
For decorative fonts I'd use the code provided by Dave Rado in his article
"Finding and replacing symbols" (haven't tested it yet). For unicode fonts
I'd use regular search / replace. In both cases, however, I'd need to have
some information to start with. Font and Char number for non-unicode fonts
and Char number for unicode fonts.

At the moment I do not have a means to come up with that information easily.

If you happen to have any suggestions (macros) for that, it would be great.

After reading your comments and those by Dave Rado on the subject, things
appear to start making at least some sense. Thanks for that.

Sergey
 
K

Klaus Linke

As mentioned before, I'd like to be able to produce my own custom macros.
For decorative fonts I'd use the code provided by Dave Rado in his article
"Finding and replacing symbols" (haven't tested it yet). For unicode fonts
I'd use regular search / replace. In both cases, however, I'd need to have
some information to start with. Font and Char number for non-unicode fonts
and Char number for unicode fonts.

At the moment I do not have a means to come up with that information
easily.

When you insert symbols from the "Insert > Symbol" dialog, what's inserted
is what I call a "protected" symbol.
If you select the symbol, Word will not show the real (decorative) font that
is applied, but instead the default font for that text. That way, when the
user applies a different font to all the text, the symbols don't change.
If you choose the Symbol font (or another decorative font) from the font
dropdown and then type something, the inserted symbols not inserted
"protected", i.e. "unprotected". They are more easily dealt with.

That's what the macro is for: It turns "protected" symbols into
"unprotected" ones, so that their real font becomes accessible.

The Char number is usually &HF000 plus the code of whatever key to type that
symbol.
Say the Greek "alpha", on the key "a" (with code &H0061), would be
ChrW(&HF061).
That's why you see ChrW(61472) = ChrW(&HF020) and ChrW(61695) = ChrW(&HF0FF)
in the macros.
From &HF000 to &HF020 there can't be symbols, because the codes from 0 to 20
are control characters.

Regards,
Klaus
 
G

Guest

When you insert symbols from the "Insert > Symbol" dialog, what's inserted
is what I call a "protected" symbol.
If you select the symbol, Word will not show the real (decorative) font
that is applied, but instead the default font for that text. That way,
when the user applies a different font to all the text, the symbols don't
change.
If you choose the Symbol font (or another decorative font) from the font
dropdown and then type something, the inserted symbols not inserted
"protected", i.e. "unprotected". They are more easily dealt with.

That's what the macro is for: It turns "protected" symbols into
"unprotected" ones, so that their real font becomes accessible.

Thanks for the explanation.

Which means, provided I understand you correctly, if I want to replace all
symbol font characters in a document with unicode ones, I would have to run
both your macros, first "unprotecting" whatever symbols might be
"protected"?
The Char number is usually &HF000 plus the code of whatever key to type
that symbol.
Say the Greek "alpha", on the key "a" (with code &H0061), would be
ChrW(&HF061).
That's why you see ChrW(61472) = ChrW(&HF020) and ChrW(61695) =
ChrW(&HF0FF) in the macros.
From &HF000 to &HF020 there can't be symbols, because the codes from 0 to
20 are control characters.

This is a bit too technical for me right now.

Regards,
Sergey
 
G

Guest

How to make your macro SymbolToUnicode work on the whole document without
selecting anything first?
 
K

Klaus Linke

How to make your macro SymbolToUnicode work on the whole document without
selecting anything first?

You can select the main document story with
ActiveDocument.Content.Select
at the beginning of the mnacro.

If you have some of the symbols in text boxes, footers, footnotes and so on,
you'd need to loop through all story ranges and run the macro on every one.
A loop over all story ranges looks something like this:

Dim myStoryRange As Range
For Each myStoryRange In ActiveDocument.StoryRanges
' select myStoryRange and call macro
While Not (myStoryRange.NextStoryRange Is Nothing)
Set myStoryRange = myStoryRange.NextStoryRange
' select myStoryRange and call macro
Wend
Next myStoryRange

Klaus
 
K

Klaus Linke

Which means, provided I understand you correctly, if I want to replace all
symbol font characters in a document with unicode ones, I would have to
run both your macros, first "unprotecting" whatever symbols might be
"protected"?

Yep. The second macro is for the "Symbol" font only. If you have other
decorative fonts to deal with (Wingdings, Zapf Dingbats...), you'd need to
get code tables for how to translate them to Unicode.
Some are on the www.unicode.org webserver.
ftp://www.unicode.org/Public/MAPPINGS/VENDORS/

Say, Zapf Dingbats in the Adobe subfolder...

[...]
This is a bit too technical for me right now.

Can't blame you <g>

All it does is explain the following piece of code in SymbolToUnicode:
' Decorative Fonts are mapped to a
' "private use" code page starting at &HF000
myCharNum = myCharNum - &HF000&

For the rest of the macro, you won't need to know about it.

Regards,
Klaus
 
G

Guest

You can select the main document story with
ActiveDocument.Content.Select
at the beginning of the mnacro.

That much I could have figured out myself.

I just prefer when possible to avoid making selections in my macros
altogether.
If you have some of the symbols in text boxes, footers, footnotes and so
on, you'd need to loop through all story ranges and run the macro on every
one.
A loop over all story ranges looks something like this:

Dim myStoryRange As Range
For Each myStoryRange In ActiveDocument.StoryRanges
' select myStoryRange and call macro
While Not (myStoryRange.NextStoryRange Is Nothing)
Set myStoryRange = myStoryRange.NextStoryRange
' select myStoryRange and call macro
Wend
Next myStoryRange

Thanks for the tip.

Regards,
Sergey
 

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