0

So I've success navigated to a website, clicked the download icon button, and successfully clicked the "Save" and "Open" popup dialogue in IE11 to open a .CSV file in Excel.

The problem is that if I add even a single line of code after that, with the exception of msgbox, the Excel file just won't open.

I've tried all of the following in Excel VBA to no avail:

DoEvents, Application.Wait, Application.Visible = True, Application.ScreenUpdating = True, TimeDelay subroutine that uses Timer, Application.EnableEvents = True

Set iuiAutoCore = New CUIAutomation

lWindowNum = ieApp.HWND
'Call MsgBox(Hex(lWindowNum))

lWindowNum = FindWindowEx(lWindowNum, 0, "Frame Notification Bar", "")
'Call MsgBox(Hex(lWindowNum))

If lWindowNum = 0 Then: Exit Sub

SetForegroundWindow (lWindowNum)

' Click Save
Set iuiAutoCondition = iuiAutoCore.CreatePropertyCondition(ByVal UIA_NamePropertyId, "Save")

Set iuiButton = iuiAutoCore.ElementFromHandle(ByVal lWindowNum).FindFirst(TreeScope_Subtree, iuiAutoCondition)

Set iuiInvokePattern = iuiButton.GetCurrentPattern(UIA_InvokePatternId)
iuiInvokePattern.Invoke

TimeDelay (1)

' Click Open
Set iuiAutoCondition = iuiAutoCore.CreatePropertyCondition(ByVal UIA_NamePropertyId, "Open")

Set iuiButton = iuiAutoCore.ElementFromHandle(ByVal lWindowNum).FindFirst(TreeScope_Subtree, iuiAutoCondition)

Set iuiInvokePattern = iuiButton.GetCurrentPattern(UIA_InvokePatternId)
iuiInvokePattern.Invoke

' Cannot add any more code after this, otherwise the downloaded Excel spreadsheet will not open

I expect the IE11's download dialog box's "Save" and "Open" to be clicked, and a .CSV to be opened in Excel, which does happen.

However, I cannot add any more lines of code after that, otherwise Excel won't open.

  • 1
    use selenium basic vba – QHarr May 14 '19 at 15:51
  • Thanks, but I tried using the OpenSource Selenium VBA library found on GitHub, but it's very buggy and fails to even open the alternate browser (Chrome). – FinancialProgrammer May 14 '19 at 16:27
  • I think it is quite stable. I use it all the time no problem. I suspect your problems may (may not!) be related to installation and dependencies. For example, with Chrome you need a fairly recent Chrome version, the latest ChromeDriver.exe should also be in the selenium folder. – QHarr May 14 '19 at 16:28
  • Yeah you're right about Chrome being outdated; looks like the System Admin disabled auto-updates. I mean everything in the code above works; I'm just not sure why the CSV file doesn't open until the subroutine/function ends. – FinancialProgrammer May 14 '19 at 17:54
  • Have you tried introducing a DoEvents or delay before attempting next line of code after open? – QHarr May 14 '19 at 17:55
  • Yup, I tried a combination of DoEvents and other delay mechanisms; I did notice though that if I put a message box at the end of the code, the CSV file doesn't appear nor open until after I close that message box. It looks like the instance of opening the CSV file is queued until after all VBA code has been ran. Perhaps that's just the multi-threading/concurrency limitation in this case. – FinancialProgrammer May 14 '19 at 18:06

0 Answers0