0

I'm using the code snippet from here Automate saveas dialouge for IE9 (vba) To invoke the open/save actions on the IEs download notification, with a few minor changes.

Specifically I use "Open".

It works fine, except I can't tell whether or not the file has been downloaded - if I have code running after the Download segment, then it fails as the workbook is not open yet.

I cannot use any further Do While loops because it occupies the excel/VBA thread, and the files refuses to open until the Macro has finished, which it doesnt as it waits for the workbook to open => infinite loop.

I tried a Do While loop with a check to see if there was an increase in open workbook count.

How can I detect that a download has finished/a new workbook is open and hence hang my code until that time?

Epiquin
  • 23
  • 7
  • Instead of "Open" why not "Save" it and then open the file via code? – Siddharth Rout Jun 08 '17 at 19:01
  • I was just considering that - the problems are that the file name is partially randomly generated, and I still don't know if the file finished downloading, nor the folder where it's going to be downloaded. I supposed I can try poking around for a workbook.open(downloaded file). If you happen to know how to get the file name from the FrameNotification bar, that would help. – Epiquin Jun 08 '17 at 19:05
  • 1
    Sorry, I do not have IE9. I have IE 11. But since you have the `hWnd` from `h = FindWindowEx(h, 0, "Frame Notification Bar", vbNullString)` you can try and find the caption using the `GetWindowText API`. I did write the routine for IE6 way back in 2011. You can see how `GetWindowText API` is used to fetch the text/caption [HERE](http://www.siddharthrout.com/2011/10/23/vbavb-netvb6click-opensavecancel-button-on-ie-download-window/#prettyPhoto) for IE6 and [HERE](http://www.siddharthrout.com/2012/02/02/vbavb-netvb6click-opensavecancel-button-on-ie-download-window-part-ii/) for IE 8 – Siddharth Rout Jun 08 '17 at 19:18
  • I was looking over the GetWindowText documentation - you have to understand I'm still a rookie. According to the MSDN documentation none of the arguments are optional - I don't understand what the _Out_ LPTSTR lpString is supposed to be, and it appears it will truncate the text no matter what as I have no way of knowing the full length of the string – Epiquin Jun 08 '17 at 19:19
  • I posted a new comment while you were typing. You many want to go through that? – Siddharth Rout Jun 08 '17 at 19:20
  • Doesn't seem to do anything... I've attached a pastebin https://pastebin.com/NT4u5b1p Im using the shell to connect to an active instance of IE and get the ie.hwnd that way, then I proceed to follow the code outlined in your links (thank you btw), it doesn't seem like the Block2 is failing as it's not printing anything in the debug Screen and it appears that the shell is returning the correct IE process. From that I am assuming that the GetWindowText is returning nothing – Epiquin Jun 08 '17 at 19:45

0 Answers0