write the symbol with mass number and atomic number

This macro will generate the symbol above in Arial font 11 rather than the Cambria Math (sic) italics which Equations produces. There is a message box asking for the atomic number (only from 1 to 20) and typing in 12 will return the symbol above.

Sub SymbolsByBigAl()
'make popup box
10 Dim Message, Title, MyValue
Message = "enter the atomic number (1-20 only)" & Chr(13) & Chr(10) & "21 = sulfate" _
& Chr(13) & Chr(10) & "22 = nitrate" & Chr(13) & Chr(10) & "23 = carbonate"
Title = "Big Al's symbol generator"

'deal with inputs
MyValue = InputBox(Message, Title, MyValue)
If MyValue = 1 Then GoTo 100
If MyValue = 2 Then GoTo 200
If MyValue = 3 Then GoTo 300
If MyValue = 4 Then GoTo 400
If MyValue = 5 Then GoTo 500
If MyValue = 6 Then GoTo 600
If MyValue = 7 Then GoTo 700
If MyValue = 8 Then GoTo 800
If MyValue = 9 Then GoTo 900
If MyValue = 10 Then GoTo 1000
If MyValue = 11 Then GoTo 1100
If MyValue = 12 Then GoTo 1200
If MyValue = 13 Then GoTo 1300
If MyValue = 14 Then GoTo 1400
If MyValue = 15 Then GoTo 1500
If MyValue = 16 Then GoTo 1600
If MyValue = 17 Then GoTo 1700
If MyValue = 18 Then GoTo 1800
If MyValue = 19 Then GoTo 1900
If MyValue = 20 Then GoTo 2000
If MyValue = 21 Then GoTo 2100
If MyValue = 22 Then GoTo 2200
If MyValue = 23 Then GoTo 2300
If MyValue = "" Then GoTo 5000


'deal with wrong inputs
BeepMsg "you were told to choose 1 to 23, numpty"
GoTo 10

'write symbols
100 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="1"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="1"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="H"
GoTo 5000

200 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="2"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="4"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="He"
GoTo 5000

300 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="3"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="7"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Li"
GoTo 5000

400 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="4"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="9"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Be"
GoTo 5000

500 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="5"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="11"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="B"
GoTo 5000

600 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="6"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="12"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="C"
GoTo 5000

700 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="7"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="14"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="N"
GoTo 5000

800 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="8"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="16"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="O"
GoTo 5000

900 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="9"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="19"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="F"
GoTo 5000

1000 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="10"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="20"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Ne"
GoTo 5000

1100 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="11"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="23"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Na"
GoTo 5000

1200 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="12"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="24"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Mg"
GoTo 5000

1300 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="13"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="27"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Al"
GoTo 5000

1400 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="14"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="28"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Si"
GoTo 5000

1500 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="15"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="31"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="P"
GoTo 5000

1600 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="16"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="32"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="S"
GoTo 5000

1700 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="17"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="35"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Cl"
GoTo 5000

1800 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="18"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="40"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Ar"
GoTo 5000

1900 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="19"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="39"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="K"
GoTo 5000

2000 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add Range:=Selection.Range, Type:= _
        wdOMathFunctionScrPre
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="20"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="40"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Ca"
GoTo 5000

2100 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add(Selection.Range, _
        wdOMathFunctionScrSubSup).ScrSubSup.AlignScripts = False
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="SO"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="4"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="2-"
GoTo 5000
   
2200 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add(Selection.Range, _
        wdOMathFunctionScrSubSup).ScrSubSup.AlignScripts = False
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="NO"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="3"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="-"
GoTo 5000

2300 Selection.OMaths.Add Range:=Selection.Range
Selection.OMaths(1).Functions.Add(Selection.Range, _
        wdOMathFunctionScrSubSup).ScrSubSup.AlignScripts = False
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.TypeText Text:="CO"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="3"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="2-"
GoTo 5000

5000

'sort out italics and font
Dim equation As OMath
For Each equation In ActiveDocument.OMaths
        equation.Range.Font.Italic = False
Next equation

Selection.WholeStory
    Selection.Font.Name = "Arial"

End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: