VBA Internet Explorer自动化 - 选择“打开”或"另存为"下载文件时

时间:2018-04-23 20:54:47

标签: vba

试图想出一种自动化的方法" Open"或者"另存为"从公司内部网站打开文件时。我使用以下脚本打开文件:

Public Sub OpenURL()

Dim myURL As Long
myURL = ShellExecute(0, "Open", "https://bankofamerica.xxxx.com/sso/bankofamerica/respInv.do?xxx)

Call Download

End Sub

第一部分执行后,我得到屏幕底部的闪烁文件对话框(下图)到目前为止很好:

File Dialog Box Prompt Image

然而,当它调用sub' Download'我从中偷走了 VBA Internet Explorer Automation - How to Select "Open" When Downloading a File

Option Explicit

Dim IE As InternetExplorer
Dim h As LongPtr
Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As LongPtr, ByVal hWnd2 As LongPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPtr

Sub Download()
    Dim o As IUIAutomation
    Dim e As IUIAutomationElement
    Set o = New CUIAutomation
    h = IE.hWnd
    h = FindWindowEx(h, 0, "Frame Notification Bar", vbNullString)
    If h = 0 Then Exit Sub

    Set e = o.ElementFromHandle(ByVal h)
    Dim iCnd As IUIAutomationCondition
    Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "Open")

    Dim Button As IUIAutomationElement
    Set Button = e.FindFirst(TreeScope_Subtree, iCnd)
    Dim InvokePattern As IUIAutomationInvokePattern
    Set InvokePattern = Button.GetCurrentPattern(UIA_InvokePatternId)
    InvokePattern.Invoke
End Sub

我没有设置'对象变量或With Block变量'以下突出显示的行出错(我错过了参考?):

Download Sub Error

我可以在shell中运行,或者如果有更好的方法,只需要弄清楚如何自动执行“另存为”和#39;或者'打开'在对话框中。

这是我关于stackoverflow的第一篇文章,如果它不完美,那么道歉。任何帮助将不胜感激。 :)

0 个答案:

没有答案