-
January 18th, 2010, 08:26 AM
#1
Get button handle at Excel 2007
Hi this an VBA question and not VB6 but as they are pretty close i chose this section make this question. I am trying to automate my own Excel application. I am using excel 2007 and i need to press an specific button at a specific ribbon. I could find the Excel handle with findWindow and then i use EnumChildWindows do get take a look at all childs class and text. But i don’t have any clue how to go on. Can anyone give me any help Thanks.
-
January 18th, 2010, 10:19 AM
#2
Re: Get button handle at Excel 2007
Hello,
I ignore the purpose of it, but here his what could be a start :
But this code on a commandbutton on your sheet :
Code:
Private Sub CommandButton5_Click()
EnumChildWindows Application.hwnd, AddressOf EnumChildProc, ByVal 0&
End Sub
and this code in a module :
Code:
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sSave As String
sSave = Space$(GetWindowTextLength(hwnd) + 1)
GetWindowText hwnd, sSave, Len(sSave)
sSave = Left$(sSave, Len(sSave) - 1)
If Trim(sSave) = "Ribbon" Then MsgBox sSave & " which has this hwnd : " & hwnd
EnumChildProc = 1
End Function
Launch and click : as you will see ===>> you will have an enumeration of all the present ribbons and their respective hwnd.
Start from tghatr.
The next step should probably be the identification of the Ribbon you are interested with.
The next would be trying to use the same method passing your ribbon's hwnd instead of application.hwnd
-
January 18th, 2010, 10:55 AM
#3
Re: Get button handle at Excel 2007
Thats exatly what i was doing and i cant get any ribbon at all. Im listing the handle the classname and the text on Excel cells... The purpose is to automate a homebroker. My broker has an COM add-in to trade directly from Excel 2007. I cant just call the functions that the buttons calls so im trying to do something like a bot so i can creat a function that when i call its send the order as i would do presing the buttons an filling textboxes. This is not illegal as i am a custommer of the broker and i am not trying to get any information a alread have or to get any user information. im just trying to creat an abstraction layer to them creat a homemade robotrader.
-
January 19th, 2010, 09:47 AM
#4
Re: Get button handle at Excel 2007
If the ribbon has an own window it will occur in the list. You only have to identify it. I don't know the class name of a ribbon control. Maybe you create a dummy form with such a control only and try your finder with this one to determine the class name.
But if the button you want is windowless you can not obtain an hWnd for it and your automation will fail. Also I don't know if maybe the complete ribbon is windowless.
What type of control is that exactly?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|