Sub SCTC() Dim Mycal As Double, MyValue As Double, CalValue As Double, SelVal As Single, InSin As String If Selection.End = Selection.Start Then MsgBox "请选定需要计算的文本!": Exit Sub If Selection.Text Like "sin(*)" = True Then SelVal = CSng(Mid(Selection, 5, Len(Selection) - 5)) MyValue = SelVal * 3.14159265358979 / 180 CalValue = Round(Sin(MyValue), 13) If Abs(CalValue) < 1 Then Selection.InsertAfter "=0" & CalValue Else Selection.InsertAfter "=" & CalValue End If Exit Sub End If If Selection.Text Like "cos(*)" = True Then SelVal = CSng(Mid(Selection, 5, Len(Selection) - 5)) MyValue = SelVal * 3.14159265358979 / 180 MyValue = SelVal * 3.14159265358979 / 180 CalValue = Round(Cos(MyValue), 13) If Abs(CalValue) < 1 Then Selection.InsertAfter "=0" & CalValue Else Selection.InsertAfter "=" & CalValue End If Exit Sub End If If Selection.Text Like "tan(*)" = True Then SelVal = CSng(Mid(Selection, 5, Len(Selection) - 5)) MyValue = (SelVal * 3.14159265358979 / 180) MyValue = SelVal * 3.14159265358979 / 180 CalValue = Round(Tan(MyValue), 13) If Abs(CalValue) < 1 Then Selection.InsertAfter "=0" & CalValue Else Selection.InsertAfter "=" & CalValue End If Exit Sub End If If Selection.Text Like "cot(*)" = True Then SelVal = CSng(Mid(Selection, 5, Len(Selection) - 5)) MyValue = Round(SelVal * 3.14159265358979 / 180, 13) MyValue = SelVal * 3.14159265358979 / 180 CalValue = Round(1 / Tan(MyValue), 13) If Abs(CalValue) < 1 Then Selection.InsertAfter "=0" & CalValue Else Selection.InsertAfter "=" & CalValue End If Exit Sub End If If Selection.Text Like "[!A-Z]*" = True Then Selection.InsertAfter "=" & Selection.Calculate End If Exit Sub End Sub 感于楼主的执著,但计算终非WORD所长,勉力而作,仅供参考!(真正的计算,还应该要考虑出错的判断和处理,此处打马虎过去也!),而且只作了四个三角函数和一个四则运算,且不能连续计算,请注意.
[此贴子已经被konggs于2006-8-18 9:23:55编辑过] |