G
Guest
Dear bunch of (lower level) chemists,
Inspired by dear Bernard Liengme in this NG
(http://www.microsoft.com/communitie...&p=1&tid=da3e000f-3961-442d-8680-a3d352859e6d)
I have accomplished his hints into an elaborated subroutine. I think it’s
been rewarding, at least Microsoft should acknowledge. The result follows.
I’m happy to share it with you; though many of yours have undoubtedly
succeeded in making the analogue. For many others it may save time. In any
case, it should help to lift the standard of our presentations. In spite of
the fact that we are admonished from many people to avoid Excel in technical
applications at all. But Excel is so simple and everybody has it.
Still, did anybody offered so much effort to find out another "chemistry"
font with better types? ChemFont97, as here applied, looks rather amateurish
(moreover "the developer passed away"), especially as you inspect its normal
size.
Regards
Petr
Sub ChemistryLegend()
' Petr Bezucha, 2007
' Sub converts a text (chemical formula) contained in a
' selected cell, which was regularly written in the basic font
' with all appropriate numerals as subscripts or superscripts,
' into the "chemistry" font, with built-in sub-
' or superscript characters.
' In this way the converted text can be referenced in
' - a chart legend,
' - an arbitrary cell,
' without loosing its conventional, legible form.
' The target destination item (legend, cell) must be, of
' course, formatted in the same or akin font. Such twins used
' here are True Type Fonts:
' "Chemistry SansSerif" and "Chemistry Serif",
' http://www.scs-intl.com/frameload.htm?/chemfont.htm
' which were made to approach Arial and Times New Roman types.
' Sub proceeds from the proposal of Prof Bernard Liengme.
' Sub does not check whether the selected font has been installed.
' First of code numbers of super- and subscript ranks in
' "chemistry" True Type Fonts:
Const SuperBegin As Long = 128, SubBegin As Long = 144
Dim T As Variant, I As Long, Cha As Characters, TFontName _
As String, ChFontName As String
Set T = Selection
'Selection between the "chemistry" fonts according to the
'original font:
TFontName = T.Cells.Font.Name
If Left(TFontName, 5) = "Arial" Then
ChFontName = "Chemistry SansSerif"
Else
ChFontName = "Chemistry Serif"
End If
'Conversion of numerals codes into the later "chemistry" ones:
For I = 1 To Len(T)
Set Cha = T.Cells.Characters(I, 1)
If IsNumeric(Cha.Caption) Then
If Cha.Font.Superscript = True Then
Cha.Text = Chr(CInt(Cha.Caption) + SuperBegin)
End If
If Cha.Font.Subscript = True Then
Cha.Text = Chr(CInt(Cha.Caption) + SubBegin)
End If
End If
Next I
'Removal of all sub- and superscripts and conversion into the
'"chemistry" font:
With T.Cells.Font
.Subscript = False
.Superscript = False
.Name = ChFontName
End With
End Sub
Inspired by dear Bernard Liengme in this NG
(http://www.microsoft.com/communitie...&p=1&tid=da3e000f-3961-442d-8680-a3d352859e6d)
I have accomplished his hints into an elaborated subroutine. I think it’s
been rewarding, at least Microsoft should acknowledge. The result follows.
I’m happy to share it with you; though many of yours have undoubtedly
succeeded in making the analogue. For many others it may save time. In any
case, it should help to lift the standard of our presentations. In spite of
the fact that we are admonished from many people to avoid Excel in technical
applications at all. But Excel is so simple and everybody has it.
Still, did anybody offered so much effort to find out another "chemistry"
font with better types? ChemFont97, as here applied, looks rather amateurish
(moreover "the developer passed away"), especially as you inspect its normal
size.
Regards
Petr
Sub ChemistryLegend()
' Petr Bezucha, 2007
' Sub converts a text (chemical formula) contained in a
' selected cell, which was regularly written in the basic font
' with all appropriate numerals as subscripts or superscripts,
' into the "chemistry" font, with built-in sub-
' or superscript characters.
' In this way the converted text can be referenced in
' - a chart legend,
' - an arbitrary cell,
' without loosing its conventional, legible form.
' The target destination item (legend, cell) must be, of
' course, formatted in the same or akin font. Such twins used
' here are True Type Fonts:
' "Chemistry SansSerif" and "Chemistry Serif",
' http://www.scs-intl.com/frameload.htm?/chemfont.htm
' which were made to approach Arial and Times New Roman types.
' Sub proceeds from the proposal of Prof Bernard Liengme.
' Sub does not check whether the selected font has been installed.
' First of code numbers of super- and subscript ranks in
' "chemistry" True Type Fonts:
Const SuperBegin As Long = 128, SubBegin As Long = 144
Dim T As Variant, I As Long, Cha As Characters, TFontName _
As String, ChFontName As String
Set T = Selection
'Selection between the "chemistry" fonts according to the
'original font:
TFontName = T.Cells.Font.Name
If Left(TFontName, 5) = "Arial" Then
ChFontName = "Chemistry SansSerif"
Else
ChFontName = "Chemistry Serif"
End If
'Conversion of numerals codes into the later "chemistry" ones:
For I = 1 To Len(T)
Set Cha = T.Cells.Characters(I, 1)
If IsNumeric(Cha.Caption) Then
If Cha.Font.Superscript = True Then
Cha.Text = Chr(CInt(Cha.Caption) + SuperBegin)
End If
If Cha.Font.Subscript = True Then
Cha.Text = Chr(CInt(Cha.Caption) + SubBegin)
End If
End If
Next I
'Removal of all sub- and superscripts and conversion into the
'"chemistry" font:
With T.Cells.Font
.Subscript = False
.Superscript = False
.Name = ChFontName
End With
End Sub