RataVa

Window Handle in VBA

4 posts in this topic

#1 ·  Posted

My first post, please forgive any transgressions

Trying to reference windows using the window handle, I think I have the syntax right, and the handle returned matches the spy value, I would be grateful for any advice

    Dim oAuto As Object
    Set oAuto = New AutoItX3
    With oAuto
        While Title = ""
            Hndl = .WinGetHandle(ThisWorkbook.Name)
            Title = .WinGetTitle(Hndl)
            MsgBox (Title)
            MsgBox (.WinGetTitle(ThisWorkbook.Name) & " " & Hndl)
            x = x + 1
        Wend
    End With
End Sub

Share this post


Link to post
Share on other sites



#2 ·  Posted

Oh dear, first post and I didn't really say what was wrong!

 

The line

Title = .WinGetTitle(Hndl)

Never returns a value

Share this post


Link to post
Share on other sites

#3 ·  Posted

Hello. AutoIt COM Object seems to be  partially written so dont expect it works exactly as AutoIt normal Scripts. There are may COM functions that will not work. You would need to do something like this to solve your issue.

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Function WinGetTitle(ByVal hwnd As String) As String
    Dim MyStr As String
    MyStr = String$(260, vbNullChar)
    GetWindowText CLng("&H" & Mid(hwnd, 3)), MyStr, 260
    MyStr = Left$(MyStr, InStr(MyStr, Chr$(0)) - 1)
    WinGetTitle = MyStr
End Function

Sub Test()
Dim oAuto As Object
    Set oAuto = New AutoItX3
    With oAuto
    'While Title = ""
            Hndl = .WinGetHandle(ThisWorkbook.Name)
            MsgBox (WinGetTitle(Hndl))
    ' Wend
    End With
End Sub

Saludos

Share this post


Link to post
Share on other sites

#4 ·  Posted

Thank you Danyfirex,

For a while I thought the Internet was ignoring me.

This worked well and I shall restart my efforts to run Autoit from Excel!

 

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now