Search code examples
excelvbainternet-explorervbscript

Excel VBA - Two IE popups with same title


I am writing a VBA automation of IE. App is looking for particular ticket number and attempts to assign it to a user. Once button on the webpage is clicked, it might, under some conditions, return up to two alerts, both with same window title ("Message from webpage"), that require pressing OK button.

I am able to catch first pop up, but am unable to handle second one. I think the best way to deal with the issue would be reading message from these popups, but I have no idea, how to do this. It appears that both wscripts are catching first popup, and are unable to detect second one. Would you be able to help, please?

I have tried with the below, but no luck:


            '' If ticket was found and is not assigned to any user, run script to handle popup
            If sBut(currentPos + 11).innerHTML <> currentUser Then
                pid = Shell("wscript.exe ""pathToScript\msgClick.vbs""")
            End If

                pid2 = Shell("wscript.exe ""pathToScript\itemClaimed.vbs""")
                zBut = sBut(currentPos + 13).getElementsByTagName("input")
                zBut.Click

Once zBut is clicked and both popus show up, script handles only first one, leaving second untouched.

Below is code for msgClick.vbs (and itemClaimed.vbs, both are the same - I thought that running two separate files could help)

Set wshShell = CreateObject("WScript.Shell")

Do
    windowLookUp = wshShell.AppActivate("Message from webpage")
    
Loop Until windowLookUp = True
    WScript.sleep 500
    windowLookUp = wshShell.AppActivate("Message from webpage")
    If windowLookUp = True then
        windowLookUp = wshShell.AppActivate("Message from webpage")
        WScript.Sleep 10
        wshShell.SendKeys "{enter}"
    end if


Solution

  • Silly me. Instead of running two scripts from VBA, one can be launched from VBA, and other one just after first one is executed. Works like a charm.

    Set wshShell = CreateObject("WScript.Shell")
    
    Do
        windowLookUp = wshShell.AppActivate("Message from webpage")
        
    Loop Until windowLookUp = True
        WScript.sleep 500
        windowLookUp = wshShell.AppActivate("Message from webpage")
        If windowLookUp = True then
            windowLookUp = wshShell.AppActivate("Message from webpage")
            WScript.Sleep 10
            wshShell.SendKeys "{enter}"
            
            dim objShell
            Set objShell = Wscript.CreateObject("WScript.Shell")
            objShell.Run "pthToScript\itemClaimed.vbs"
            
            Set objShell = Nothing
        end if