【问题标题】:Getting information from a popup produced by another application从另一个应用程序生成的弹出窗口中获取信息
【发布时间】:2017-08-04 16:49:44
【问题描述】:

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

[]

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

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

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

感谢您的帮助:)

【问题讨论】:

  • 它来自一个用 VB6 编写的程序。它产生自己的弹出窗口。它看起来像一个自定义对话框。
  • 我是这个论坛的新手,有没有办法提交图片?
  • 添加了对话框的图片。我需要的是日期和时间。
  • 如何将信息发送到其他应用程序?
  • 使用.sendkey 命令。

标签: excel excel-2016 vba


【解决方案1】:

这对我有用,使用来自 .NET Windows Forms 项目的测试对话框。

对话框标题是“测试员!”它包含一个带有一些文本的标签。 您的情况会有所不同:您需要确定包含所需文本的控件的“类”。您可以为此使用 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

Spy++ - 按 Alt+F3 然后将“目标”拖到对话框中以在树中找到它。

【讨论】:

  • 你太棒了,先生,我会试一试 :) 非常感谢!
猜你喜欢
  • 1970-01-01
  • 2018-05-10
  • 2015-06-23
  • 1970-01-01
  • 1970-01-01
  • 2012-12-12
  • 1970-01-01
  • 2019-04-14
  • 1970-01-01
相关资源
最近更新 更多