|
楼主 |
发表于 2017-6-5 19:10
|
显示全部楼层
请问如何把world中出现的算式自动计算出答案
做成窗体了,支持四则运算,显示,隐藏以及删除答案,再次感谢阿杜老师的帮助。
- Sub 批量计算(ss)
- Dim n, t, str$, D As Object, W As Object
- Set D = CreateObject("HTMLFILE"): Set W = D.parentWindow
- D.write "<Script></Script>"
- sr$ = "0123456789()."
- With ActiveDocument.Range(0, 0)
- n = 0
- t = Timer
- Do While .MoveUntil("=")
- .MoveStartWhile sr & "++--*×X÷/", wdBackward
- str = Replace(Replace(.Text, "+", "+"), "-", "-")
- str = Replace(str, "X", "*")
- str = Replace(str, "÷", "/")
- str = Replace(str, "/", "/")
-
- .Collapse 0: .Move , 1: .MoveEndWhile sr
-
- If ss = 1 Then '计算答案
- 'MsgBox (str)
-
- 'MsgBox (W.eval("" & str & ""))
- .Text = W.eval("" & str & "")
- .Font.ColorIndex = wdRed
-
- CommandButton3.Visible = True
- CommandButton2.Visible = True
- CommandButton3.Caption = "隐藏答案"
-
-
-
- ElseIf ss = 2 Then
- .Text = "" '删除答案
- CommandButton3.Visible = False
- CommandButton2.Visible = False
-
- ElseIf ss = 3 Then .Font.Color = RGB(255, 255, 255) '隐藏答案
-
- ElseIf ss = 4 Then .Font.Color = RGB(221, 3, 13) '显示答案
-
- End If
-
- .Collapse 0
- n = n + 1
- Loop
- End With
-
- Call Fonts
-
- Label1.Caption = "共" & n & "题;用时" & Timer - t
-
- End Sub
- Private Sub CommandButton1_Click()
- Call 批量计算(1)
- End Sub
- Private Sub CommandButton2_Click()
- Call 批量计算(2)
- End Sub
- Private Sub CommandButton3_Click()
- If CommandButton3.Caption = "隐藏答案" Then
- Call 批量计算(3)
- CommandButton3.Caption = "显示答案"
- Else
- Call 批量计算(4)
- CommandButton3.Caption = "隐藏答案"
- End If
- End Sub
- Sub Fonts()
- With Selection
- .WholeStory
- .Font.Size = 12
- End With
- End Sub
复制代码 |
|