theflyingdutchdog
New Member
- Joined
- Jun 2, 2017
- Messages
- 39
So I have symbols that I have to convert to LaTeX values. I thought I would be able to run my program for replacement and then use Word to format the super/subscripts using _{^&}. I know that isn't elegant, but I need this by Friday and it would work.
Well, when I ran my program, it changed the subscripts back to normal font.
Is there a way to keep the formatting of my original text (keep it in subscript form) after running my Replace functions program?
Otherwise, is there anyway to program VBA to recognize sub/superscripts and allow me to black _{ } and ^{ } around them?
Thank you so much for any help.
Here is the program I have now:
Sub Latexualize()
Dim rng As Range
Dim cell As Range
Dim txt As String
Dim wsOut As Worksheet
Set rng = ActiveSheet.Cells.SpecialCells(xlCellTypeConstants)
Set wsOut = ActiveWorkbook.Sheets.Add(Type:=xlWorksheet)
For Each cell In rng
txt = cell.Value
' Add Replace() steps below, as needed
txt = Replace(txt, "", "\backslash")
txt = Replace(txt, "_", "\_")
txt = Replace(txt, "#", "\#")
txt = Replace(txt, ChrW(916), "\Delta")
txt = Replace(txt, ChrW(&H221E), "\infty")
' Output to new worksheet
wsOut.Cells(cell.Row, cell.Column).Value = txt
Next
End Sub
Well, when I ran my program, it changed the subscripts back to normal font.
Is there a way to keep the formatting of my original text (keep it in subscript form) after running my Replace functions program?
Otherwise, is there anyway to program VBA to recognize sub/superscripts and allow me to black _{ } and ^{ } around them?
Thank you so much for any help.
Here is the program I have now:
Sub Latexualize()
Dim rng As Range
Dim cell As Range
Dim txt As String
Dim wsOut As Worksheet
Set rng = ActiveSheet.Cells.SpecialCells(xlCellTypeConstants)
Set wsOut = ActiveWorkbook.Sheets.Add(Type:=xlWorksheet)
For Each cell In rng
txt = cell.Value
' Add Replace() steps below, as needed
txt = Replace(txt, "", "\backslash")
txt = Replace(txt, "_", "\_")
txt = Replace(txt, "#", "\#")
txt = Replace(txt, ChrW(916), "\Delta")
txt = Replace(txt, ChrW(&H221E), "\infty")
' Output to new worksheet
wsOut.Cells(cell.Row, cell.Column).Value = txt
Next
End Sub