翻訳と英文作成に役立つマクロその2(化学式や単位や自作文字列の上付きと下付き部分を自動で変換するマクロ)
https://gyazo.com/36524915b57f77ad076c64cd5de7edd4
code:subscript&superscript_adjustment
Sub H2OCO2等変換()
'
' 下付きと上付き調整Macro
' written by Tomoyuki Shishido
'
Dim rng As Range
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "H2O2"
Do While rng.Find.Execute = True
rng.Characters(2).Font.Subscript = True
rng.Characters(4).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "H2O"
Do While rng.Find.Execute = True
rng.Characters(2).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "CO2"
Do While rng.Find.Execute = True
rng.Characters(3).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "Mg2+"
Do While rng.Find.Execute = True
rng.Characters(3).Font.Superscript = True
rng.Characters(4).Font.Superscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "Ca2+"
Do While rng.Find.Execute = True
rng.Characters(3).Font.Superscript = True
rng.Characters(4).Font.Superscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "MgSO4"
Do While rng.Find.Execute = True
rng.Characters(5).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "Al2O3"
Do While rng.Find.Execute = True
rng.Characters(3).Font.Subscript = True
rng.Characters(5).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "SiO2"
Do While rng.Find.Execute = True
rng.Characters(4).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "KH2PO4"
Do While rng.Find.Execute = True
rng.Characters(3).Font.Subscript = True
rng.Characters(6).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "K2HPO4"
Do While rng.Find.Execute = True
rng.Characters(2).Font.Subscript = True
rng.Characters(6).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "NaNO3"
Do While rng.Find.Execute = True
rng.Characters(5).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "CaCl2"
Do While rng.Find.Execute = True
rng.Characters(5).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "NaHCO3"
Do While rng.Find.Execute = True
rng.Characters(6).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "Na2O3"
Do While rng.Find.Execute = True
rng.Characters(3).Font.Subscript = True
rng.Characters(5).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "K2HPO4"
Do While rng.Find.Execute = True
rng.Characters(2).Font.Subscript = True
rng.Characters(6).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "NaNO3"
Do While rng.Find.Execute = True
rng.Characters(5).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "K2SO4"
Do While rng.Find.Execute = True
rng.Characters(2).Font.Subscript = True
rng.Characters(5).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "Na2EDTA"
Do While rng.Find.Execute = True
rng.Characters(3).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "FeCl3"
Do While rng.Find.Execute = True
rng.Characters(5).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "MnCl2"
Do While rng.Find.Execute = True
rng.Characters(5).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "CuSO4"
Do While rng.Find.Execute = True
rng.Characters(5).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "ZnSO4"
Do While rng.Find.Execute = True
rng.Characters(5).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "H3BO3"
Do While rng.Find.Execute = True
rng.Characters(2).Font.Subscript = True
rng.Characters(5).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "B12"
Do While rng.Find.Execute = True
rng.Characters(2).Font.Subscript = True
rng.Characters(3).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "H2SO4"
Do While rng.Find.Execute = True
rng.Characters(2).Font.Subscript = True
rng.Characters(5).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "CHCl3"
Do While rng.Find.Execute = True
rng.Characters(5).Font.Subscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "cm2"
Do While rng.Find.Execute = True
rng.Characters(3).Font.Superscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "cm-1"
Do While rng.Find.Execute = True
rng.Characters(3).Font.Superscript = True
rng.Characters(4).Font.Superscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "mm2"
Do While rng.Find.Execute = True
rng.Characters(3).Font.Superscript = True
Loop
Set rng = ActiveDocument.Range(0, 0)
rng.Find.Text = "M-1s-1"
Do While rng.Find.Execute = True
rng.Characters(2).Font.Superscript = True
rng.Characters(3).Font.Superscript = True
rng.Characters(5).Font.Superscript = True
rng.Characters(6).Font.Superscript = True
Loop
End Sub