Mixed fractions with sub/superscript formatting.

G

Guest

I type a great many mixed fractions (measurements). Sometimes WORD auto
formats fractions like 1/4 but not others like 9/16. How do I add
superscripts/subscript auto formating to these fractions so that 1 15/16 is
easier to read?
 
H

Helmut Weber

Hi Jay,

or something like this,
might be a possible extension to Suzanne's article.

Sub Macro7()
Dim l As Long ' length of expression found
Dim p As Long ' position of "/"
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "[0-9]{1,}/[0-9]{1,}"
.MatchWildcards = True
While .Execute
p = InStr(rDcm.Text, "/")
l = Len(rDcm.Text)
rDcm.End = rDcm.Start + p - 1
rDcm.Select
rDcm.Font.Size = 8 ' or a fraction of font size
rDcm.Font.Position = 3 ' or a fraction of font size
rDcm.Start = rDcm.Start + p
rDcm.End = rDcm.End + l - p
rDcm.Select
rDcm.Font.Size = 8 ' or a fraction of font size
rDcm.Collapse Direction:=wdCollapseEnd
Wend
End With
End Sub

Dates could be excluded easily,
sure not expressions like 10 to the power of 1/13.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
G

Guest

Dear Helmut: You're probably right but I have no idea what you are talking
about as I'm no programmer. I'm a woodworker who writes a lot of
instructional material that includes many fractional dimensions--I'd just
like to type in 1/2's, 1/4's, 8th's, 16th's, 32nd's, and 64th's and have them
all appear the same without jumping through hoops. I'll play around a bit
with auto correct but I don't have the time or patience to write a line of
code everytime I need a fraction. But thanks for the input--it keeps me on
top of just how much I need to learn.
 
G

Graham Mayor

There is a variety of possibilities - see:

http://www.gmayor.com/createfraction.htm
or
http://gregmaxey.mvps.org/Formatted_Fractions.htm
or
http://www.word.mvps.org/FAQs/Formatting/CreateFraction.htm

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Dear Helmut: You're probably right but I have no idea what you are
talking about as I'm no programmer. I'm a woodworker who writes a
lot of instructional material that includes many fractional
dimensions--I'd just like to type in 1/2's, 1/4's, 8th's, 16th's,
32nd's, and 64th's and have them all appear the same without jumping
through hoops. I'll play around a bit with auto correct but I don't
have the time or patience to write a line of code everytime I need a
fraction. But thanks for the input--it keeps me on top of just how
much I need to learn.

Helmut Weber said:
Hi Jay,

or something like this,
might be a possible extension to Suzanne's article.

Sub Macro7()
Dim l As Long ' length of expression found
Dim p As Long ' position of "/"
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "[0-9]{1,}/[0-9]{1,}"
.MatchWildcards = True
While .Execute
p = InStr(rDcm.Text, "/")
l = Len(rDcm.Text)
rDcm.End = rDcm.Start + p - 1
rDcm.Select
rDcm.Font.Size = 8 ' or a fraction of font size
rDcm.Font.Position = 3 ' or a fraction of font size
rDcm.Start = rDcm.Start + p
rDcm.End = rDcm.End + l - p
rDcm.Select
rDcm.Font.Size = 8 ' or a fraction of font size
rDcm.Collapse Direction:=wdCollapseEnd
Wend
End With
End Sub

Dates could be excluded easily,
sure not expressions like 10 to the power of 1/13.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Helmut Weber

Hi WoodOne,

actually, I've tried to address Jay Freedman.

But since you are writing,
I'll play around a bit with auto correct
but I don't have the time or patience to write
a line of code everytime I need a fraction.
But thanks for the input--it keeps me on
top of just how much I need to learn. !!!

I think, you might still be interested,
and not know yet, how simple it can be.
Sure, only in a way. ;-)

There was I time, when I didn't know
how to insert a floppy disc ito a disc drive.

You need to know nothing about programming,
therefore there are no comments in the code.

Get to the VBA-Editor: [alt F11].
Copy the code from the posting into it.
Close it. Assign a shortcut to "Fractions",
by the menu "Tools", "Customize".
Click on "Keyboard".
Select "Macros" in the left listbox.
Select "Fractions" in the right listbox.
Click in "Press new shortcut key".
Press e.g. [F12]. Click "assign".
....
You will have to press F12 every now and then.

Maybe there is someone around, to help you,
with the VBA-Editor and assigning a shortcut.

Sub Fractions()
Dim l As Long
Dim p As Long
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
Dim h As Long
h = Selection.Start
ResetSearch
With rDcm.Find
.Text = "[0-9]{1,}/[0-9]{1,}"
.MatchWildcards = True
While .Execute
If rDcm.Next <> "/" Then
p = InStr(rDcm.Text, "/")
l = Len(rDcm.Text)
rDcm.End = rDcm.Start + p - 1
rDcm.Select
rDcm.Font.Size = 8
rDcm.Font.Position = 3
rDcm.Start = rDcm.Start + p
rDcm.End = rDcm.End + l - p
rDcm.Select
rDcm.Font.Size = 8
rDcm.Collapse Direction:=wdCollapseEnd
End If
Wend
End With
ResetSearch
ActiveDocument.Characters(h).Select
Selection.Collapse Direction:=wdCollapseEnd
End Sub
' ---
Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub

Don't give up.

--
Greetings from a bavarian hobby woodworker

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
G

Guest

Dear Helmut: I appreciate your time and I'll certainly be playing around
with this a bit . . . but not on your level of expertise 'til next month (or
a little later) as this month I'm getting ready for a toy production (some
300 toys over a weekend with 25-30 people involved). Thanks again for your
input and happy woodworking!

Helmut Weber said:
Hi WoodOne,

actually, I've tried to address Jay Freedman.

But since you are writing,
I'll play around a bit with auto correct
but I don't have the time or patience to write
a line of code everytime I need a fraction.
But thanks for the input--it keeps me on
top of just how much I need to learn. !!!

I think, you might still be interested,
and not know yet, how simple it can be.
Sure, only in a way. ;-)

There was I time, when I didn't know
how to insert a floppy disc ito a disc drive.

You need to know nothing about programming,
therefore there are no comments in the code.

Get to the VBA-Editor: [alt F11].
Copy the code from the posting into it.
Close it. Assign a shortcut to "Fractions",
by the menu "Tools", "Customize".
Click on "Keyboard".
Select "Macros" in the left listbox.
Select "Fractions" in the right listbox.
Click in "Press new shortcut key".
Press e.g. [F12]. Click "assign".
....
You will have to press F12 every now and then.

Maybe there is someone around, to help you,
with the VBA-Editor and assigning a shortcut.

Sub Fractions()
Dim l As Long
Dim p As Long
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
Dim h As Long
h = Selection.Start
ResetSearch
With rDcm.Find
.Text = "[0-9]{1,}/[0-9]{1,}"
.MatchWildcards = True
While .Execute
If rDcm.Next <> "/" Then
p = InStr(rDcm.Text, "/")
l = Len(rDcm.Text)
rDcm.End = rDcm.Start + p - 1
rDcm.Select
rDcm.Font.Size = 8
rDcm.Font.Position = 3
rDcm.Start = rDcm.Start + p
rDcm.End = rDcm.End + l - p
rDcm.Select
rDcm.Font.Size = 8
rDcm.Collapse Direction:=wdCollapseEnd
End If
Wend
End With
ResetSearch
ActiveDocument.Characters(h).Select
Selection.Collapse Direction:=wdCollapseEnd
End Sub
' ---
Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub

Don't give up.

--
Greetings from a bavarian hobby woodworker

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
G

Guest

Graham: Thanks for the information. I've checked two of the sites you
provided and they seem to have information that is certainly a good start.
As I mentioned to Helmut I've got a full plate the next couple of weeks so I
doubt I'll be back to it right away . . . but this has been a frustrating
problem for some time so I'm very appreciative of the information. Thanks
again.

Graham Mayor said:
There is a variety of possibilities - see:

http://www.gmayor.com/createfraction.htm
or
http://gregmaxey.mvps.org/Formatted_Fractions.htm
or
http://www.word.mvps.org/FAQs/Formatting/CreateFraction.htm

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Dear Helmut: You're probably right but I have no idea what you are
talking about as I'm no programmer. I'm a woodworker who writes a
lot of instructional material that includes many fractional
dimensions--I'd just like to type in 1/2's, 1/4's, 8th's, 16th's,
32nd's, and 64th's and have them all appear the same without jumping
through hoops. I'll play around a bit with auto correct but I don't
have the time or patience to write a line of code everytime I need a
fraction. But thanks for the input--it keeps me on top of just how
much I need to learn.

Helmut Weber said:
Hi Jay,

or something like this,
might be a possible extension to Suzanne's article.

Sub Macro7()
Dim l As Long ' length of expression found
Dim p As Long ' position of "/"
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "[0-9]{1,}/[0-9]{1,}"
.MatchWildcards = True
While .Execute
p = InStr(rDcm.Text, "/")
l = Len(rDcm.Text)
rDcm.End = rDcm.Start + p - 1
rDcm.Select
rDcm.Font.Size = 8 ' or a fraction of font size
rDcm.Font.Position = 3 ' or a fraction of font size
rDcm.Start = rDcm.Start + p
rDcm.End = rDcm.End + l - p
rDcm.Select
rDcm.Font.Size = 8 ' or a fraction of font size
rDcm.Collapse Direction:=wdCollapseEnd
Wend
End With
End Sub

Dates could be excluded easily,
sure not expressions like 10 to the power of 1/13.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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