首页 > 解决方案 > 如何使用 VBA 代码自动化登录页面,如共享图像中所示

问题描述

我需要自动化一个需要登录插件的工作流程。在这个插件中有一个登录按钮,我需要点击它,以便出现登录弹出窗口。之后我需要输入用户名和密码。然后在最后点击继续按钮。

我尝试将“SetCursorPos”用于单击事件,但输入文本部分对我不起作用。

我还尝试使用“FindWindow”和“SendMessage”api 来处理弹出窗口,但我无权访问 SPY++ 来了解应用程序的类名然后要知道类名我使用了“WindowFromPoint”/“GetCursorPos”/“GetClassName”

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long



Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Label3.Caption = "KeyCode = " & KeyCode
End Sub

Private Sub Form_Load()
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 1
Timer1.Interval = 100
End Sub

Private Sub Timer1_Timer()
Dim b As POINTAPI
Dim r, s, t As String
GetCursorPos b
Label1.Caption = "Mouse Position =" & " { " & b.X & " , " & b.Y & " }"
r = WindowFromPoint(b.X, b.Y)
t = Space(128)
s = GetClassName(r, t, 128)
Label2.Caption = "ClassName = " & t
End Sub

但仍面临 Label1.Caption 中的问题或有时在 bX 或 bY 上出现错误

我尝试了很多次,但仍然没有得到结果。

在此处输入图像描述

标签: excelvbawinapi

解决方案


推荐阅读