Quote Originally Posted by Shred Dude View Post
Your issue sounds like your ieApp object is loisng focus when the pop up occurs and you have no reference to the new window, and thus it's HTML in order to manipulate it's controls.

You need to declare your ieApp object "withevents" and also set up another one for the pop-up. Then you can monitor the primary ieApp's events for the appearance of the pop up, get a reference to it and do what you need in the pop up.

The code below will give you a framework to work within. Given the withevents declarations, you either need to put this code into a Sheet Module or create Class module that you instantiate and control it from. The with events declarations won't compile in a Standard Module.

[VBA]Option Explicit



'Reference to Microsoft Internet Controls
'Reference to Microsoft HTML Object Library as well
Private WithEvents ieApp As InternetExplorer
Private WithEvents iePopup As InternetExplorer

Private Sub ieApp_NewWindow2(ppDisp As Object, Cancel As Boolean)

'Event Handler to monitor your primary ieApp's New Window event
'When this event fires, start up a new instance of an IE object
Set iePopup = New InternetExplorer
'set the popup window to the new instance of your iePopup object
Set ppDisp = iePopup
End Sub

Public Sub getData()
Dim URL As String

URL = "htt...."

Set ieApp = New InternetExplorer

With ieApp 'go to your page
.Visible = True
.navigate URL
Do While .Busy Or .ReadyState <> 4: DoEvents: Loop


'do what you have to do to get to the pop up window
ieApp.Document.all.Item("ctl00_ContentPlaceHolder1_btnAction").Click

'Wait for the pop up window
Do Until ie.ReadyState = READYSTATE_COMPLETE _
And Not ie.Busy _
And (Not iePopup Is Nothing)
DoEvents
Loop

While iePopup.ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend

'You should now have the ability to reference the pop up window directly
With iePopup
'Do what you want from pop up window
Debug.Print "Pop Up's URL is: " & .LocationURL
End With

'close Pop Up Window
iePopup.Quit
Set iePopup = Nothing
End If

'Continue on with your primary window ieApp...

Do While .Busy Or .ReadyState <> 4: DoEvents: Loop

End With 'ieApp

ieApp.Quit
Set ieApp = Nothing

End Sub


[/VBA]

Thanks for the above suggestion. I copied the entire above code (with some modifications regarding URL) in the Class module and then I called the above function getData from a standard Macro. But the error appeared saying "Sub or Function not defined".

Please help. Thanks,.