My question is about IE automation in VBA. I got my code to work through the pages and click on the download button. After searching for hours, I came across this page on StackOverFlow:
Automate saveas dialogue for IE9 (vba)
The code they suggested worked perfectly for saving pending files that need to be downloaded... However, I want to save the file into a specific directory (save as). Questions:
How can I change the following code, so it will perform what I need to do? I tried to change "Save" to "Save As" on line 3, but it didn't work.
If number 1 is not possible, how can I modify the code, so I can get the name of the file and the exact folder address in which the file has been saved into?
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, "Save")
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