Fractions: whole numbers to proper fractions

G

gianluca

MS Word 2004 (MS Word 2003 is also on board)

As a cookbook editor, I receive countless submissions with the most
common fractions entered as whole numbers. I have quick correct to
convert these if I am typing them myself however I need a way to have
Word make the conversion on a per document basis rather than on a
manual fraction by fraction basis as I do now. In the old WordPerfect
days, running spell check would do this as well as convert generic
quotes to typographer's quotes; Word does neither.

Google has not been my friend in this search. Appropriate suggestions
from this forum are invited and appreciated.

Thank you.
 
S

Suzanne S. Barnhill

AutoFormat (NOT AutoFormat As You Type) will convert 1/2, 1/4, and 3/4 as
well as the quotation marks. Just make sure to disable all the other things
you DON'T want AutoFormat to do!

To convert other fractions, you'll need to use Replace (you can copy a
specific fraction to the Clipboard and use ^c if necessary, but you should
also be able to copy/paste the characters for 1/3 and 2/3 and 1/8 into the
"Replace with" box). See
http://word.mvps.org/FAQs/Formatting/CreateFraction.htm

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
P

Peter T. Daniels

Cookbooks use a limited set of fractions -- half, quarters, eighths,
and if you're really getting exotic, thirds and maybe even sixths --
and all of them (except the sixths) are provided for in basic Windows
fonts -- Arial, Lucida Sans, Times New Roman; in Word2007, Calibri (I
don't know about what's included in basic Mac fonts) at Unicode 00BC -
00BE and 2153 - 215E.

Someone familiar with macros could easily write one that will convert
any of those typed as "1/2" or "7/8" etc. to the corresponding
fraction characters with the click of a single button.

For when you type recipes yourself, you could make them into
AutoCorrect entries, or you could assign special keyboard shortcuts to
them in Insert Symbol (the first three are in "Latin-1 Supplement" and
the others are in "Number Forms").
 
P

Pesach Shelnitz

Hi,

The following macro will replace all occurrences of the 9 whole-number
fractions commonly used in cookbooks 1/4, 1/2, 3/4, 1/3, 2/3, 1/8, 3/8, 5/8,
and 7/8 by the single-character equivalents ¼, ½, ¾, â…“, â…”, â…›, â…œ, â…, and â…ž in
a document.

Sub ReplaceFractions()
Dim FindArray As Variant
Dim ReplaceArray As Variant
Dim MyRange As Range
Dim i As Long
Dim pos As Long

FindArray = Array("1/4", "1/2", "3/4", "1/3", "2/3", _
"1/8", "3/8", "5/8", "7/8")
ReplaceArray = Array(ChrW(&HBC), ChrW(&HBD), ChrW(&HBE), _
ChrW(&H2153), ChrW(&H2154), ChrW(&H215B), _
ChrW(&H215C), ChrW(&H215D), ChrW(&H215E))
Set MyRange = ActiveDocument.Range
pos = MyRange.start
For i = 0 To 8
MyRange.start = pos
With MyRange.Find
.Text = FindArray(i)
.Replacement.Text = ReplaceArray(i)
.Forward = True
.Execute Replace:=wdReplaceAll
End With
Next
End Sub

For instructions for installing macros, see
http://www.gmayor.com/installing_macro.htm
 
S

Suzanne S. Barnhill

The problem with such a macro is that it will not replace, say, "1-1/2" with
"1½," which will be desired.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
G

Graham Mayor

If indeed that is how the fractions are listed then it needs but a small
adjustment to the arrays. The following should work either way

FindArray = Array("-1/4", "-1/2", "-3/4", "-1/3", "-2/3", _
"-1/8", "-3/8", "-5/8", "-7/8", "1/4", "1/2", "3/4", "1/3", "2/3", _
"1/8", "3/8", "5/8", "7/8")

ReplaceArray = Array(ChrW(&HBC), ChrW(&HBD), ChrW(&HBE), _
ChrW(&H2153), ChrW(&H2154), ChrW(&H215B), _
ChrW(&H215C), ChrW(&H215D), ChrW(&H215E), _
ChrW(&HBC), ChrW(&HBD), ChrW(&HBE), _
ChrW(&H2153), ChrW(&H2154), ChrW(&H215B), _
ChrW(&H215C), ChrW(&H215D), ChrW(&H215E))


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Pesach Shelnitz

Hi,

If you change the size of the arrays, you should also change the line

For i = 0 To 8

to

For i = 0 To UBound(FindArray)

Actually, I shouldn't have hard-coded array size in the first place.
 
G

Graham Mayor

Good thinking - I missed that :(

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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