4

On a 64-bit system with MS Excel 2010 and IE11 I'm using this code to automate download process from a website:

hWnd = FindWindowEx(IE.hWnd, 0, "Frame Notification Bar", vbNullString)

If hWnd Then
    hWnd = FindWindowEx(hWnd, 0&, "Button", "Save")
End If

If hWnd Then
    SetForegroundWindow (hWnd)
    Sleep 600
    SendMessage hWnd, BM_CLICK, 0, 0
End If

Everything goes OK until the Frame Notification Bar appears. I'm getting the HWND of this window, but can't get the HWND of the "Save" button, so that I can send click to it.

pnuts
  • 58,317
  • 11
  • 87
  • 139
Vahagn Sargsyan
  • 385
  • 1
  • 4
  • 14
  • The cheezy answer is to use sendkeys to send Alt+S to the download confirmation but the real answer is to implement urlddownloadtofile or catch a stream with xmlhttp and save it. –  Jul 18 '15 at 09:41
  • i dont want to use send keys, cause they seem to work sometimes. And i dont want to show the whole process and turn of the visbility. – Vahagn Sargsyan Jul 18 '15 at 09:44

2 Answers2

3

If somebody is still trying to find the solution, for IE11 it's here.

On the very first line of the code of Vahagn Sargsyan above, instead of "Frame Notification Bar" get the exact title of the dialog box, which might be in English "View Downloads - Internet Explorer". This allows you to grab the right hWnd.

Because in IE11 there no more button accelerator to Save files, follow the solution posted here by pmr.

From pmr code, just get the following lines:

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

This should solve your issue. This unlocked the situation for me with French localisation.

Jerome
  • 366
  • 5
  • 17
  • Hi Jerome, i tried to change the text to find but the Hwnd always return 0 hence it is exiting the Sub. but im sure i used the Correct words – deejay Jun 27 '21 at 15:50
-1

I'm assuming you're talking about that little frame that pops up at the bottom of IE giving you options to Open, Save or Cancel. If so, you might wanna check out another answer to a similar question asked here.

A secondary solution would be a more complicated one (here), but works nonetheless. You'll have to import the modules from the workbook provided in this forum (you'll need to signup for membership though, but its free so just do it.) and that'll do basically what you need, albeit in a way that allows you more flexibility (choose filepath, filename, etc) and also a little more convoluted.

Either way, hope I helped.

Community
  • 1
  • 1