【发布时间】:2020-09-05 06:35:40
【问题描述】:
我正在自动化一个过程,我必须从 Internet Explorer 中的网站下载文件我有以下代码,一旦下载弹出,点击“保存”按钮。
Sub thing()
'Find download message and click Save to download file
Dim o As IUIAutomation
Set o = New CUIAutomation
Dim Completed As String
Dim h As Long
Dim ie As InternetExplorer
Dim html As HTMLDocument
Sleep 1000
Set ie = CreateObject("InternetExplorer.application")
Do
h = ie.hwnd
h = FindWindowEx(h, 0, "Frame Notification Bar", vbNullString)
If h <> 0 Then
Dim count As Long
count = 0
Exit Do
Else
Sleep 100
count = count + 1
End If
Loop
Dim e As IUIAutomationElement
Set e = o.ElementFromHandle(ByVal h)
Dim iCnd As IUIAutomationCondition
Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "Save")
Dim Button As IUIAutomationElement
Set Button = e.FindFirst(TreeScope_Subtree, iCnd)
Sleep 1000
Do
On Error Resume Next
Dim InvokePattern As IUIAutomationInvokePattern
Set InvokePattern = Button.GetCurrentPattern(UIA_InvokePatternId)
If Err.Number = 0 Then
On Error GoTo 0
Exit Do
Else
Sleep 100
count = count + 1
End If
On Error GoTo 0
Loop
InvokePattern.Invoke
Do
Sleep 1000
Completed = DownloadComplete()
If Completed = "Yes" Then
Exit Do
Else
End If
Loop
SendMessage h, WM_CLOSE, 0, 0
End Sub
但是,当我在家中运行此自动化时,有时单击“保存”后会出现以下弹出窗口:
如果弹出此按钮,我应该如何告诉 VBA 单击“重试”? 谢谢您的帮助!
【问题讨论】: