从另一个应用程序生成的弹出窗口获取信息

时间:2017-08-04 16:49:45

标签: excel-vba excel-2016 vba excel

我有一个Excel工作簿,它将信息发送到另一个应用程序(通过VBA),然后生成一个弹出窗口,其中包含该信息的结果,然后我需要Excel工作簿。有没有办法让Excel从其他应用程序的弹出窗口中读取信息并将其粘贴到自身?

[enter image description here]

这是对话框的图片。我需要的是它的日期和时间。

来自用VB6编写的程序。它会生成自己的弹出窗口。它看起来像一个自定义对话框。

我无法访问外部应用程序的代码。它看起来像是用VB6编写的专有程序,它有自己的功能按钮,其中一个用输入的数据进行计算,然后用计算出的数据创建一个对话框。对话框中没有用于获取数据的字段,它只是一个包含数据的框,其中包含" OK"按钮。现在,我们手动复制值,然后继续下一个计算。

感谢您的帮助:)

1 个答案:

答案 0 :(得分:1)

这对我有用,可以使用.NET Windows Forms项目中的测试对话框。

对话框标题为" Tester!"它包含一个带有一些文字的标签。 你的情况会有所不同:你需要确定"班级"控件包含您需要的文本。你可以使用Spy ++。

Public Declare Function FindWindow Lib "user32" 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

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
    (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long



Sub main()
    Dim lngHWnd As Long
    Dim lngHWndChild As Long
    Dim lngIndex As Long
    Dim lngDlgItem As Long
    Dim lngTextLength As Long
    Dim strText As String

    lngHWnd = FindWindow(vbNullString, "Tester!")

    lngHWndChild = FindWindowEx(lngHWnd, 0&, "WindowsForms10.STATIC.app.0.3ee13a2_r17_ad1", vbNullString)

    lngTextLength = GetWindowTextLength(lngHWndChild)

    strText = Space(lngTextLength)
    GetWindowText lngHWndChild, strText, lngTextLength + 1

    Debug.Print strText

End Sub

间谍++ - 按Alt + F3然后拖动"目标"到对话框中以在树中找到它。

enter image description here