Will a kind soul help to provide a vba solution to press a button (e.g 3) in Microsoft calculator without using sendkeys?

API_newnoob

New Member
Joined
Jun 6, 2020
Messages
21
Office Version
  1. 2016
Platform
  1. Windows
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?
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Is it even possible with VBA other than by using sendkeys ?
 
Upvote 0
From what i understand it should be possible with API. It is just that i am a beginner.
 
Upvote 0
@Jaafar Tribak may be the member who can help you with this
Please do NOT private message him! It's against the rules.
His alerts will tell him that I have referred to him in this thread
Good luck
 
Upvote 0
Cross posted VBA program to press a button (e.g 3) in microsoft calculator without using sendkeys - OzGrid Free Excel/VBA Help Forum

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
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.


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.
 

Attachments

  • Capture.JPG
    Capture.JPG
    67.7 KB · Views: 18
Upvote 0
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?
I think, In theory, this could be done via Microsoft Active Accessibility or UI Automation but since the user interface of MS Calculator differs dramatically from one Windows version to another it is difficult to write any useful generic vba code.
 
Upvote 0
I noticed that the Control ID is unique, is there a way of calling the Control ID?
 
Upvote 0
I noticed that the Control ID is unique, is there a way of calling the Control ID?
Which windows version do you have ? As I said, Calc.exe "Calculator" is very different in each version of Windows.

In my Windows 10, this is how Calculator looks :
Calc.png


It is very different from the old classic Calc.exe
calc-exe-2.png



As for reading the Control ID programatically, you could use use:
VBA Code:
Declare Function GetDlgCtrlID Lib "user32" (ByVal hwnd As Long) As Long
But this assumes the control has a Dialog ID which is not the case in my Windows10 caculator

Or, if you are a using SPY.exe select the element you want ,right-click it and choose Properties. You should find the Control ID Under the General tab if the control has an ID.
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,196
Latest member
Maxkapoor

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top