Dear Mr Fluff,
Thank you for your kind reminder. As a new member, I really appreciate it. Here is the link i have cross posted.
[xpost] [/xpost] Hi all, Will a kind soul help to provide a vba solution to press a button (e.g 3) in Microsoft calculator without using sendkeys?
www.ozgrid.com
As of right now, no one has posted a solution. The link below is a tutorial i am trying but failed to have a positive outcome.
Below is my failed code.
Private Const BM_CLICK = &HF5
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Sub Calculator()
Dim Program As String, TaskID As Double
Program = "calc.exe"
On Error Resume Next
AppActivate "Calculator"
If Err <> 0 Then
Err = 0
TaskID = Shell(Program, 1)
Do
DoEvents
hwindow2 = FindWindow(vbNullString, "Calculator")
Loop Until hwindow2 > 0
main_view = FindWindowEx(hwindow2, 0&, "Calcframe", vbNullString)
sub_view = FindWindowEx(main_view, 0&, "#32770", vbNullString)
sub_window = FindWindowEx(sub_view, 0&, "Button", vbNullString)
'Call SendMessage(button3window, BM_CLICK, 0, ByVal0&)
If Err <> 0 Then MsgBox "Can't start " & Program
End If
End Sub
Please pardon my bad work as i am new, I believe i am stuck because the windows are not unique.
If anyone has a solution to this problem, please feel free to post your answers. I welcome all alternatives other than sendkeys. Thank you very much.