Trying to figure out a way to automate "Open" or "Save As" when opening a file from a companies internal website. I am using the following script to open the file:
Public Sub OpenURL()
Dim myURL As Long
myURL = ShellExecute(0, "Open", "https://bankofamerica.xxxx.com/sso/bankofamerica/respInv.do?xxx)
Call Download
End Sub
Once the first part executes, I get the blinking file dialog box at the bottom of the screen (below) so far so good:
However, when it calls the sub 'Download' which I stole from 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
I get the 'Object Variable or With Block variable not set' Error on the following highlighted line (am I missing a Reference?):
I am okay running in shell or otherwise if there is a better way, just need to figure out how to automate either to 'Save As' or 'Open' in the dialog box.
This is my first post on stackoverflow, so apologies if it's not perfect. Any help would be greatly appreciated. :)