以下是引用taller在2006-12-26 21:36:20的发言:Excel本身就可以计算,为什么要舍近求远呢 精度不同,比较一下: Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Sub macro1() Dim temp As String, i As Long, j As Long Application.ScreenUpdating = False Shell "Calc.EXE", vbMinimizedNoFocus '运行计算器 For j = 1 To 20 temp = j + 100 & "y0.5=" For i = 1 To Len(temp) SendKeys Mid(temp, i, 1), True '向计算器顺序发送按键消息X (X^Y) 0.5= Next temp = String(64, Chr(0)) i = FindWindow(vbNullString, "计算器") '窗口句柄 i = FindWindowEx(i, ByVal 0&, "Edit", vbNullString) '编辑框句柄 SendMessage i, &HD, Len(temp), ByVal temp '发送编辑框文本至temp Cells(j, 1) = j + 100 & "的平方根" Cells(j, 2) = "'" & Sqr(j + 100) Cells(j, 3) = "'" & temp Next [a:c].Columns.AutoFit SendKeys "%{F4}", True '调用ALT+F4关闭计算器窗口 Application.ScreenUpdating = True End Sub |