# Fractions Macro for Word



## Saxon (Jul 2, 2005)

If you want to display fractions properly in Word here is a macro which will do just that. Type in something like 3/4 then select it with the mouse then run the Macro and the fraction will be displayed correctly. Here it is: -


Sub FmtFraction()
Dim OrigFrac As String
Dim Numerator As String, 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)
Selection.Font.Superscript = True
Selection.TypeText Text:=Numerator
Selection.Font.Superscript = False
Selection.TypeText Text:=NewSlashChar
Selection.Font.Subscript = True
Selection.TypeText Text:=Denominator
Selection.Font.Subscript = False
End Sub


----------



## rameam (Mar 15, 2003)

Thanks Saxon,

I use Word a lot, and can use that!


----------



## HLHHMC (Aug 3, 2005)

thanks ill use that as well


----------



## Nita (Feb 3, 2004)

Please explain how to use it.


----------



## Saxon (Jul 2, 2005)

One way to get this Macro into Word is as follows

1.Select the Macro shown above with the mouse and copy it.
2. Click on Tools in the Menu bar in Word then on Macro>Record new macro
3. In the Window that appears, in the box labelled Macro name type FmtFraction (no spaces) click OK
4. A small Macro recorder box will appear on screen click on the square button to stop recording.
5. Click on Tools in the Menu bar again and choose Macro>Macros, you will see FmtFraction listed in the pane, click on it then click on the Step Into button.
6. You will now be in the Visual Basic editor, scroll down till you see the Sub FmtFraction () line, delete this line carefully and everything below it
7. Paste in the Macro you copied earlier, now click on File>Save Normal in the Menu bar then on File>Close and return to Microsoft Word

Now follow the brief instruction given in my previous post. To run a Macro click Macro>Macros click on the FmtFraction macro then on the Run button. You can also create a Toolbar button to run this Macro with one click. Details of this will be given if required.


----------



## HLHHMC (Aug 3, 2005)

What if the fraction is of the form 127/5 (or any fraction that involes a numeratior larger than 9) ... it doesn't seem to work. When I run the macro with the above fraction it returns to me 1/5. It is in the correct format but obviously the wrong fraction.

Thanks for any help and good work on the above macro


----------



## Saxon (Jul 2, 2005)

Tried the 127/5 and it worked perfectly in Word 2000.


----------



## HLHHMC (Aug 3, 2005)

maybe it just doesnt work in word 97, could be the case...no worries though

thanks


----------



## Nita (Feb 3, 2004)

Thanks Saxon but there doesn't seem to be a macro option in my windws 98SE word 2000. The only time the word macro appears is when I click on customise and then commands but I can't seem to type anything in there. Any ideas


----------



## Saxon (Jul 2, 2005)

Don't you have the word Macro in the list when you click on the Tools option on the Menu bar? If not, a quick fix is click on the Customize link again then click on the Commands tab, now in the Categories list on the left click on Tools. Scroll down the list on the right till you see two entries Macroand Record Macro/Stop Recorder. With your left mouse button click and drag each of these in turn to the Tools entry in the Menu bar. The Tools list will then open and you can place each anywhere in the list and release the mouse button. Now click on close in the Customize box. You will now have the Macro entries listed under Tools and you can now create and use Macros.

If you find you more missing entries like this there is a command to reset your Toolbars etc to the Factory defaults. Just Ask.


----------



## Nita (Feb 3, 2004)

Thanks Saxon. There is a "macros" in the command tab but no "Record Macro/Stop Recorder" I don't know how to reset the toolbars.


----------



## Saxon (Jul 2, 2005)

OK, go into the Customize box again, click on the Options tab then click on the button labelled 'Reset my usage data'. A message will appear saying your Toolbars and Menus will be set to the Default, Click OK. You may need to close down Word then open it again to see the changes.


----------



## Nita (Feb 3, 2004)

Thanks for your patience. I did as you said but nothing changed even after shutting down and rebooting. I don't understand it as when I went on to help for recording macros I got the same advice as you gave me but I simply don't get the option to record macros. When I click on macros in the categories boxthe the adjacent panel shows 4 different template projects 3 of which are connected to my palm. Unfortunately I have forgotten how to do a print screen otherwise I could show you


----------



## Saxon (Jul 2, 2005)

Click on the Start button, click on Run, then Copy and Paste the line after the dotted line below into your Run box. Click OK. The /a switch will load up Word so that Normal.dot is ignored, templates in the Startup folder are ignored. Any add-in libraries (.wll files) are ignored. and user settings in the Windows Registry are ignored. 

If you can now see the Macros entry under tools in the Menu Bar there may something wrong with the Normal.dot file which Word uses as a default template, and all instances of this should be deleted from your computer. Tell me if you see the Macro Entry after using this fix below and we'll take it from there.

------------------------------------------------------------

"C:\Program Files\Microsoft Office\Office\WINWORD.EXE" /a


----------



## Nita (Feb 3, 2004)

The only thing that has changed is that when I click on macros in the command categories the right hand panel is now empty.There is still no macros when I justclick on tools.


----------



## Saxon (Jul 2, 2005)

Then it looks like you will have to repair Word. For this you will need to insert your Office CD first, cancel any windows which appear. Load up Word and on the Menu bar click on Help, make sure the Help list is fully expanded then click on 'Detect and repair..' in the list. A window will appear informing you that Word is going to be repaired click on the Start button in the window and follow the prompts.


----------



## Nita (Feb 3, 2004)

Many many thanks for your infinite patience. I followed your instructions and it worked, only one thing you did say you could show me how to put this on my tool bar if it's not too much trouble.
I really appreciate your efforts to educate a dimwit like me.


----------



## Saxon (Jul 2, 2005)

So glad it worked for you Nita. I presume by now you have managed to get that Macro into the VB Editor as described earlier and saved and named it as FmtFraction. All you need to do now is get into the Customize box again, now follow the steps below. It looks like a long list but I don't want you to miss anything.

1. Click on the Toolbars tab in the Customize box
2. Click on the New button
3. Type in a name for your new toolbar, I suggest Fractions, click OK
4. You will see a tiny Toolbar appear somewhere near the Cusomize box
5. Now click on the Commands tab in the Customize box
6. In the Categories list on the left, scroll down and click on the Macros entry.
7. In the list on the right you should find the FmtFraction in the list, it will read something like Normal.NewMacros.FmtFraction
8. Click and drag the Fmtfraction macro to your new Toolbar, then release the mouse button
9. Your Toolbar may now contain too many Words for your taste, if so click on the Modify Selection box and click on Default , a default icon will replace the text
10. You can leave it at that if you wish but if you look in the Modify Selection box list there are many options to choose another icon or edit an icon etc.
12. When you are happy with your new Toolbar simply drag it and place it anywhere on the existing Toolbar strip.
13 Close the Customize box. You are now ready to use your Toolbar macro. Select the fraction you've typed with the mouse then click on the Fraction Toolbar to display the fraction correctly.


----------



## Nita (Feb 3, 2004)

Brilliant. The deed is done again many many thanks.


----------



## shyamal (Mar 6, 2004)

Saxon, just a quick note to say that this has been a very educative thread for me. And I'm no newbie.

Cheers.


----------

