Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Formatting Fractions in PowerPoint

60 views
Skip to first unread message

sephilpot

unread,
Sep 10, 2009, 6:06:20 PM9/10/09
to
Hello.

I am trying to create a Macro that I can fun in PowerPoint to
automatically format fractions for me. I currently have a macro set
up in Word but when I copied it over to PowerPoint, it did not work.
I am pasting below what I am currently using in Word. Can someone
please correct this for me so that I may use it in PowerPoint? I do
not konw enough about Microsoft Visual Basic to do this myself.


Sub FmtFraction()
Dim OrigFrac As String
Dim Numerator As String

Dim Denominator As String
Dim NewSlashChar As String
Dim SlashPos As Integer
NewSlashChar = ChrW(&H2044)
OrigFrac = Selection
SlashPos = InStr(OrigFrac, "/")
Numerator = Left(OrigFrac, SlashPos - 1)
Denominator = Right(OrigFrac, Len(OrigFrac) - SlashPos)
With Selection
.Font.Superscript = True
.TypeText Text:=Numerator
.Font.Superscript = False
.TypeText Text:=NewSlashChar
.Font.Subscript = True
.TypeText Text:=Denominator
.Font.Subscript = False
End With
End Sub


Thanks a million!

Sue Ellen

KC

unread,
Sep 11, 2009, 3:43:02 AM9/11/09
to
Hi Sue,
try the below code, i'm sure you can further clean up the code, i've tweaked
your code to give you an idea...

Sub FmtFraction()
Dim OrigFrac As String
Dim Numerator As String

Dim intSelStart As Integer

Dim Denominator As String
Dim NewSlashChar As String
Dim SlashPos As Integer
NewSlashChar = ChrW(&H2044)

OrigFrac = ActiveWindow.Selection.TextRange


SlashPos = InStr(OrigFrac, "/")
Numerator = Left(OrigFrac, SlashPos - 1)
Denominator = Right(OrigFrac, Len(OrigFrac) - SlashPos)

intSelStart = ActiveWindow.Selection.TextRange.Start
With ActiveWindow.Selection.TextRange
.Font.Superscript = msoTrue

ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=intSelStart + Len(Numerator), Length:=1).Select
ActiveWindow.Selection.TextRange.Font.Superscript = msoFalse

ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=intSelStart + Len(Numerator) + 1, Length:=Len(Denominator)).Select
ActiveWindow.Selection.TextRange.Font.Subscript = msoTrue

ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=intSelStart + Len(Numerator) + 2 + Len(Denominator), Length:=1).Select
ActiveWindow.Selection.TextRange.Font.Superscript = msoFalse
End With

End Sub

hope this will give you some idea?

regards,
-kc
*Click YES if this helps

John Wilson

unread,
Sep 11, 2009, 7:45:01 AM9/11/09
to
Try this

Sub frac()
Dim oTxtr As TextRange
Dim iPos As Integer
If ActiveWindow.Selection.Type <> ppSelectionText Then Exit Sub
Set oTxtr = ActiveWindow.Selection.TextRange
iPos = InStr(oTxtr, "/")
If iPos < 1 Then Exit Sub
With oTxtr
.Characters(1, iPos - 1).Font.Superscript = True
.Characters(iPos) = ChrW(&H2044)
.Characters(iPos + 1, Len(oTxtr)).Font.Subscript = True
End With
End Sub
--
john ATSIGN PPTAlchemy.co.uk

Free PPT Hints, Tips and Tutorials
http://www.pptalchemy.co.uk/powerpoint_hints_and_tips_tutorials.html
PPTLive Atlanta Oct 11-14 2009

Steve Rindsberg

unread,
Sep 11, 2009, 1:40:51 PM9/11/09
to

The code here is similar but allows you to choose the offset up/down
rather than relying on PPT's default sub/superscript offset. With a
little tweakage, you could set the font size too.

Create "proper" fractions
http://www.pptfaq.com/FAQ00596.htm

In article <5a86eb8e-a32f-4faf-b590-


==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/

PPTools add-ins for PowerPoint
http://www.pptools.com/

Don't Miss the PPTLive User Conference! Atlanta | Oct 11-14

0 new messages