O2 (Oxegen)

G

Graham Mayor

Investigate Subscript and Superscript font attributes (CTRL+Shift++ and
CTRL+=)
If you have lots of chemical formulae to write you may find - 'Format part
of a found text string in a list of items' at
http://www.gmayor.com/word_vba_examples.htm useful

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

macropod

If you have lots of chemical formulae to write you may find - 'Format part of a found text string in a list of items'

Or the following macro, written specifically for chemical formulae:
Sub ChemicalFormatter()
Dim oRng As Range, fRng As Range, bState As Boolean
Application.ScreenUpdating = False
Select Case MsgBox("Do you want to process the whole document?", _
vbYesNoCancel + vbQuestion, "Chemical Formatter")
Case vbYes
bState = True
Case vbNo
bState = False
Case vbCancel
End
End Select
With Selection
Set oRng = .Range
With .Find
.ClearFormatting
.Text = "[A-Za-z)][0-9]{1,}"
.MatchWildcards = True
.Wrap = wdFindContinue
.Forward = True
Do While .Execute = True
Set fRng = ActiveDocument.Range(Start:=Selection.Start + 1, End:=Selection.End)
If bState = False Then
If fRng.Start >= oRng.End Then Exit Do
If fRng.End >= oRng.End Then fRng.End = oRng.End
End If
fRng.Font.Subscript = True
fRng.Collapse Direction:=wdCollapseEnd
Loop
End With
End With
oRng.Select
Set fRng = Nothing
Set oRng = Nothing
Application.ScreenUpdating = True
End Sub
The above macro will search the active document for all numbers preceded by a letter or a right bracket, and subscript just the
numbers.

If your document has other alphanumeric strings in which a number follows a letter (eg Table cell references), you'll need to select
only the range(s) containing the text to be converted and answer 'No' to the prompt.
 
G

Graham Mayor

A problem with chemical formulae is that they don't all use subscript.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

If you have lots of chemical formulae to write you may find -
'Format part of a found text string in a list of items'

Or the following macro, written specifically for chemical formulae:
Sub ChemicalFormatter()
Dim oRng As Range, fRng As Range, bState As Boolean
Application.ScreenUpdating = False
Select Case MsgBox("Do you want to process the whole document?", _
vbYesNoCancel + vbQuestion, "Chemical Formatter")
Case vbYes
bState = True
Case vbNo
bState = False
Case vbCancel
End
End Select
With Selection
Set oRng = .Range
With .Find
.ClearFormatting
.Text = "[A-Za-z)][0-9]{1,}"
.MatchWildcards = True
.Wrap = wdFindContinue
.Forward = True
Do While .Execute = True
Set fRng = ActiveDocument.Range(Start:=Selection.Start + 1,
End:=Selection.End) If bState = False Then
If fRng.Start >= oRng.End Then Exit Do
If fRng.End >= oRng.End Then fRng.End = oRng.End
End If
fRng.Font.Subscript = True
fRng.Collapse Direction:=wdCollapseEnd
Loop
End With
End With
oRng.Select
Set fRng = Nothing
Set oRng = Nothing
Application.ScreenUpdating = True
End Sub
The above macro will search the active document for all numbers
preceded by a letter or a right bracket, and subscript just the
numbers.
If your document has other alphanumeric strings in which a number
follows a letter (eg Table cell references), you'll need to select
only the range(s) containing the text to be converted and answer 'No'
to the prompt.


Graham Mayor said:
Investigate Subscript and Superscript font attributes (CTRL+Shift++
and CTRL+=) If you have lots of chemical formulae to write you may find -
'Format part of a found text string in a list of items' at
http://www.gmayor.com/word_vba_examples.htm useful --
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

macropod

Hi Graham,

There's always a fly in the ointment, so to speak. AFAIK, most (if not all) of the chemical formulae numbers that aren't subscripted
are at the start of the formula. My macro leaves those numbers alone.

--
Cheers
macropod
[Microsoft MVP - Word]


Graham Mayor said:
A problem with chemical formulae is that they don't all use subscript.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

If you have lots of chemical formulae to write you may find -
'Format part of a found text string in a list of items'

Or the following macro, written specifically for chemical formulae:
Sub ChemicalFormatter()
Dim oRng As Range, fRng As Range, bState As Boolean
Application.ScreenUpdating = False
Select Case MsgBox("Do you want to process the whole document?", _
vbYesNoCancel + vbQuestion, "Chemical Formatter")
Case vbYes
bState = True
Case vbNo
bState = False
Case vbCancel
End
End Select
With Selection
Set oRng = .Range
With .Find
.ClearFormatting
.Text = "[A-Za-z)][0-9]{1,}"
.MatchWildcards = True
.Wrap = wdFindContinue
.Forward = True
Do While .Execute = True
Set fRng = ActiveDocument.Range(Start:=Selection.Start + 1,
End:=Selection.End) If bState = False Then
If fRng.Start >= oRng.End Then Exit Do
If fRng.End >= oRng.End Then fRng.End = oRng.End
End If
fRng.Font.Subscript = True
fRng.Collapse Direction:=wdCollapseEnd
Loop
End With
End With
oRng.Select
Set fRng = Nothing
Set oRng = Nothing
Application.ScreenUpdating = True
End Sub
The above macro will search the active document for all numbers
preceded by a letter or a right bracket, and subscript just the
numbers.
If your document has other alphanumeric strings in which a number
follows a letter (eg Table cell references), you'll need to select
only the range(s) containing the text to be converted and answer 'No'
to the prompt.


Graham Mayor said:
Investigate Subscript and Superscript font attributes (CTRL+Shift++
and CTRL+=) If you have lots of chemical formulae to write you may find -
'Format part of a found text string in a list of items' at
http://www.gmayor.com/word_vba_examples.htm useful --
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


sogani wrote:
How to write chemical symbol like Silica (SiO2)
 
G

Graham Mayor

'Fraid not all - see the examples at
http://en.wikipedia.org/wiki/Chemical_formula
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Hi Graham,

There's always a fly in the ointment, so to speak. AFAIK, most (if
not all) of the chemical formulae numbers that aren't subscripted are
at the start of the formula. My macro leaves those numbers alone.

Graham Mayor said:
A problem with chemical formulae is that they don't all use
subscript. --
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

If you have lots of chemical formulae to write you may find -
'Format part of a found text string in a list of items'

Or the following macro, written specifically for chemical formulae:
Sub ChemicalFormatter()
Dim oRng As Range, fRng As Range, bState As Boolean
Application.ScreenUpdating = False
Select Case MsgBox("Do you want to process the whole document?", _
vbYesNoCancel + vbQuestion, "Chemical Formatter")
Case vbYes
bState = True
Case vbNo
bState = False
Case vbCancel
End
End Select
With Selection
Set oRng = .Range
With .Find
.ClearFormatting
.Text = "[A-Za-z)][0-9]{1,}"
.MatchWildcards = True
.Wrap = wdFindContinue
.Forward = True
Do While .Execute = True
Set fRng = ActiveDocument.Range(Start:=Selection.Start + 1,
End:=Selection.End) If bState = False Then
If fRng.Start >= oRng.End Then Exit Do
If fRng.End >= oRng.End Then fRng.End = oRng.End
End If
fRng.Font.Subscript = True
fRng.Collapse Direction:=wdCollapseEnd
Loop
End With
End With
oRng.Select
Set fRng = Nothing
Set oRng = Nothing
Application.ScreenUpdating = True
End Sub
The above macro will search the active document for all numbers
preceded by a letter or a right bracket, and subscript just the
numbers.
If your document has other alphanumeric strings in which a number
follows a letter (eg Table cell references), you'll need to select
only the range(s) containing the text to be converted and answer
'No' to the prompt.


Investigate Subscript and Superscript font attributes (CTRL+Shift++
and CTRL+=) If you have lots of chemical formulae to write you may
find - 'Format part of a found text string in a list of items' at
http://www.gmayor.com/word_vba_examples.htm useful --
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


sogani wrote:
How to write chemical symbol like Silica (SiO2)
 
M

macropod

Hi Graham,

The wikipedia article seems to suggest that only ions and isotopes aren't covered by my macro. Covering all possibilities seems
beyond the abilities of a macro - some human intervention will be required, particularly for ions and isotopes.

--
Cheers
macropod
[Microsoft MVP - Word]


Graham Mayor said:
'Fraid not all - see the examples at http://en.wikipedia.org/wiki/Chemical_formula
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Hi Graham,

There's always a fly in the ointment, so to speak. AFAIK, most (if
not all) of the chemical formulae numbers that aren't subscripted are
at the start of the formula. My macro leaves those numbers alone.

Graham Mayor said:
A problem with chemical formulae is that they don't all use
subscript. --
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


macropod wrote:
If you have lots of chemical formulae to write you may find -
'Format part of a found text string in a list of items'

Or the following macro, written specifically for chemical formulae:
Sub ChemicalFormatter()
Dim oRng As Range, fRng As Range, bState As Boolean
Application.ScreenUpdating = False
Select Case MsgBox("Do you want to process the whole document?", _
vbYesNoCancel + vbQuestion, "Chemical Formatter")
Case vbYes
bState = True
Case vbNo
bState = False
Case vbCancel
End
End Select
With Selection
Set oRng = .Range
With .Find
.ClearFormatting
.Text = "[A-Za-z)][0-9]{1,}"
.MatchWildcards = True
.Wrap = wdFindContinue
.Forward = True
Do While .Execute = True
Set fRng = ActiveDocument.Range(Start:=Selection.Start + 1,
End:=Selection.End) If bState = False Then
If fRng.Start >= oRng.End Then Exit Do
If fRng.End >= oRng.End Then fRng.End = oRng.End
End If
fRng.Font.Subscript = True
fRng.Collapse Direction:=wdCollapseEnd
Loop
End With
End With
oRng.Select
Set fRng = Nothing
Set oRng = Nothing
Application.ScreenUpdating = True
End Sub
The above macro will search the active document for all numbers
preceded by a letter or a right bracket, and subscript just the
numbers.
If your document has other alphanumeric strings in which a number
follows a letter (eg Table cell references), you'll need to select
only the range(s) containing the text to be converted and answer
'No' to the prompt.


Investigate Subscript and Superscript font attributes (CTRL+Shift++
and CTRL+=) If you have lots of chemical formulae to write you may
find - 'Format part of a found text string in a list of items' at
http://www.gmayor.com/word_vba_examples.htm useful --
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


sogani wrote:
How to write chemical symbol like Silica (SiO2)
 

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