分离两个构建的方程式

Separating two built equations

我已经构建了一个表格,它将构建两个方程,一个包含原始方程,一个包含动态变量。尽管两个方程都正确构建,但方程 #2 不会在下一行构建。

我试过在两个方程之间使用 selection.paragraphs.add,但没有成功。

有什么想法吗?感谢您的帮助。

Set objRange1 = Selection.Range
objRange1.Text = "BSA" & "(m" & "^2" & ")" & " = " & ChrW(8730) & "(" & "(" & "Height" & "_(cm)" _
     & " * " & "Weight" & "_(kg)" & ")" & "/3600" & ")"
Set objRange1 = Selection.OMaths.Add(objRange1)
Set objEq1 = objRange1.OMaths(1)
objEq1.BuildUp

Set objRange = Selection.Range
objRange.Text = "BSA" & "(m" & "^2" & ")" & " = " & ChrW(8730) & "(" & "(" & intHeight _
& "_cm" & " * " & dblweight & "_kg" & ")" & "/3600" & ")"
Set objRange = Selection.OMaths.Add(objRange)
Set objeq = objRange.OMaths(1)
objeq.BuildUp

一般来说,在 Word 中使用范围比使用选择要好。例如:

Sub Insert2Eqs1()
Dim dblWeight As Double
Dim intHeight As Long
Dim objEq As Word.OMath
Dim objRange As Word.Range
Set objRange = Selection.Range
' You might need to adjust this depending on exactly where you want the 
' equations to appear in relation to the selection
objRange.InsertParagraph
objRange.InsertParagraphBefore
' You now have a range containing two paragraph marks
objRange.Collapse wdCollapseStart
objRange.Text = "BSA" & "(m" & "^2" & ")" & " = " & ChrW(8730) & "(" & "(" & "Height" & "_(cm)" _
     & " * " & "Weight" & "_(kg)" & ")" & "/3600" & ")"
Set objEq = objRange.OMaths.Add(objRange).OMaths(1)
objEq.BuildUp
Set objRange = objEq.Range
objRange.Collapse wdCollapseEnd
' If you use + 1, you get two equations, one below the other
objRange.Start = objRange.Start + 1
' if you use + 2, you get two equations separated by a paragraph on its own
objRange.Start = objRange.Start + 2
intHeight = 0#
dblWeight = 2.45
objRange.Text = "BSA" & "(m" & "^2" & ")" & " = " & ChrW(8730) & "(" & "(" & intHeight _
& "_cm" & " * " & dblWeight & "_kg" & ")" & "/3600" & ")"
Set objEq = objRange.OMaths.Add(objRange).OMaths(1)
objEq.BuildUp
Set objEq = Nothing
Set objRange = Nothing
End Sub