【发布时间】:2019-02-03 14:54:11
【问题描述】:
我正在尝试创建 VBA 以在 Supercript 和下标之前和之后插入。我的代码如下。
Public Sub MySubscriptSuperscript()
Dim myRange As Word.Range, myChr
For Each myRange In ActiveDocument.StoryRanges
Do
For Each myChr In myRange.Characters
If myChr.Font.Superscript = True Then
myChr.Font.Superscript = False
myChr.InsertBefore "<sup>"
myChr.InsertAfter "</sup>"
End If
If myChr.Font.Subscript = True Then
myChr.Font.Subscript = False
myChr.InsertBefore "<sub>"
myChr.InsertAfter "</sub>"
End If
Next
Set myRange = myRange.NextStoryRange
Loop Until myRange Is Nothing
Next
End Sub
此代码适用于上标和下标的每个字符。
但是,我正在寻找在完整的上标/下标单词/字母之前和之后插入标签的 VBA。
例子
C12H22O11 和 x23 + y39 7 + x67
VBA 上面给出以下输出
C<sub>1</sub><sub>2</sub>H<sub>2</sub><sub>2</sub>O<sub>1</sub><sub>1</sub><sub> </sub><sub> </sub> and x<sup>2</sup><sup>3</sup> + y<sup>3</sup><sup>9</sup><sup>7</sup> + x<sup>6</sup><sup>7</sup>
但我正在寻找这个输出
C<sub>12</sub>H<sub>22</sub>O<sub>11</sub> and x<sup>23</sup> + y<sup>397</sup> + x<sup>67</sup>
请指导,如何实现。
【问题讨论】:
标签: vba ms-word subscript superscript