Thread: O2 (Oxegen)
View Single Post
  #3   Report Post  
Posted to microsoft.public.word.docmanagement
macropod[_2_] macropod[_2_] is offline
external usenet poster
 
Posts: 2,059
Default O2 (Oxegen)

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.


--
Cheers
macropod
[Microsoft MVP - Word]


"Graham Mayor" wrote in message ...
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
Word MVP web site http://word.mvps.org



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