Search, Replace & Symbol, Decorative fonts

  • Follow


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/microsoft.public.word.vba.general/browse_thread/thread/ffedfe9411830efc/741c6800843c8a3d?q=%22SymbolToUnicode+replaces+any+character%22

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



0
Reply data 1/6/2010 3:52:05 PM

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.



0
Reply Utf 1/6/2010 5:54:01 PM


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



0
Reply data 1/6/2010 6:51:01 PM

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




<data.file@mail.ru> schrieb im Newsbeitrag 
news:ut2bFhujKHA.1864@TK2MSFTNGP05.phx.gbl...
>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/microsoft.public.word.vba.general/browse_thread/thread/ffedfe9411830efc/741c6800843c8a3d?q=%22SymbolToUnicode+replaces+any+character%22
>
> 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
>
>
> 

0
Reply Klaus 1/7/2010 9:33:52 AM

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



0
Reply data 1/7/2010 1:10:53 PM

> 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 

0
Reply Klaus 1/7/2010 2:52:30 PM

> 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



0
Reply data 1/7/2010 6:14:23 PM

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


0
Reply data 1/7/2010 6:32:43 PM

<data.file@mail.ru> wrote:
> 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 

0
Reply Klaus 1/7/2010 6:47:06 PM

<data.file@mail.ru> schrieb im Newsbeitrag 
news:%23su5KV8jKHA.1652@TK2MSFTNGP05.phx.gbl...
> 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 

0
Reply Klaus 1/7/2010 6:59:15 PM

> 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 


0
Reply data 1/7/2010 7:34:30 PM

10 Replies
960 Views

(page loaded in 0.354 seconds)


Reply: