Formatting Fractions in PowerPoint

S

sephilpot

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
 
K

KC

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
 
J

John Wilson

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
 

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