Re: Access popup window from IE object.



You could just Wait for the window to finish loading - if you know there
should be a window with the expected URL then you can just keep looking
until it appears (in a do...while loop or similar)

'********************
'submit the form then try to find the new window......

Dim ie2 As Object
Do
'have to wait until it's ready...
Application.Wait (Now + TimeValue("0:00:03"))
Set ie2 = GetIE("http://someserver.com/output/results.html";)
Loop While ie2 Is Nothing
Debug.Print "Got new window"
'do stuff with ie2
'********************

Tim


"Mayhew" <Mayhew@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A59EF4A3-421E-4658-8A50-8D501531E873@xxxxxxxxxxxxxxxx
This is somewhat helpful. However, I still have a very similar problem.

After the button push, this function returns "Nothing". If I put a
breakpoint after the popup is activated, and wait for it to load, this
function works.

I can't wait do the ie2.Busy test to wait for the popup to finish loading,
because the ie2 object doesn't appear to exist yet, is there a way to
pause
execution until that function will work?

"Tim Williams" wrote:

This function will return a reference to an IE window if you know the URL
(uses "like" so modify if you know the exact URL)


'*************************
Function GetIE(sLocation As String) As Object

Dim objShell As Object, o As Object
Dim sURL As String
Dim retVal As Object

Set retVal = Nothing
Set objShell = CreateObject("Shell.Application")

For Each o In objShell.Windows
sURL = ""
On Error Resume Next
sURL = o.document.Location
On Error GoTo 0
'debug.print sURL
If sURL Like sLocation & "*" Then
Set retVal = o
Exit For
End If
Next o

Set GetIE = retVal

End Function
'**************************

--
Tim Williams
Palo Alto, CA


"Mayhew" <Mayhew@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:7EA2D8FB-9119-4808-AC43-B93FECE315E6@xxxxxxxxxxxxxxxx
I'm trying to get a reference to the InternetExplorer object that pops
up
when I use VBA to fill out a form and click a link. I found the
"NewWindow2"
event, but it doesn't seem to be doing what I want.

The NewWindow2 event fires when it should, but the "ppDisp" variable is
set
to Nothing when I get into the function.

Any ideas what's going wrong?

Thanks,
Mayhew

Here's the code:
======================
Class Module IEClass:
======================
' class module "ieclass"
Public WithEvents x As InternetExplorer
Public y As InternetExplorer

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal
lParam
As Long) As Long

Private Sub x_NewWindow2(ppDisp As Object, Cancel As Boolean)
Set y = ppDisp
End Sub

Public Sub SetVisible(visible As Boolean)
x.visible = visible
End Sub


Public Sub Navigate(destURL)
x.Navigate2 destURL
LoadPage
End Sub

Public Sub LoadPage()
' Pauses execution until the browser window has finished loading
Do While x.Busy Or x.ReadyState <> READYSTATE_COMPLETE
PostMessage FindWindow("#32770", "Microsoft Internet
Explorer"),
&H10, 0&, 0&
DoEvents
Loop
End Sub


Public Function Button_name(tagType, Caption As String) As Boolean
' Clicks the element of type tagType containing Caption or returns
false if
element cannot be found
Dim Element

Button = True

Dim AllElements
Set AllElements = x.Document.getElementsByTagName(tagType)

For Each Element In AllElements
tempAlt = Element.Name
If InStr(Element.Name, Caption) > 0 Then
Call Element.Click
Call LoadPage
Exit Function
End If
Next Element
Button = False
End Function

==================
Module 'Module1'
==================
Sub URL_Test2()
Dim ie1 As New IEClass
Set ie1.x = New InternetExplorer
ie1.SetVisible True

Dim varURL As String
varURL = "http://www.weather.gov/climate/index.php?wfo=box";
ie1.Navigate varURL

With ie1.x.Document.forms(2)
.Product(1).Click
.station.Options(2).Selected = True
.recent(1).Click
.Date.Options(0).Selected = True
End With
successful = ie1.Button_name("img", "goMain")
breakPointHere = True 'for breakpoint.

End Sub





.



Relevant Pages

  • Re: Filewatch saga continues
    ... Public Sub NKWatch_Created(ByVal sender As Object, ... Dim frmFirst As New Form1 ...
    (microsoft.public.dotnet.general)
  • Re: Filewatch saga continues
    ... Public Sub NKWatch_Created(ByVal sender As Object, ... Dim frmFirst As New Form1 ...
    (microsoft.public.dotnet.general)
  • Re: API to find position of active cell no longer working in 2007.
    ... the EXCELE window remains as does its window coordinates ... Private Sub CommandButton1_Click ... Dim hWndXLDesk As Long ... Dim nRow As Long, nCol As Long ...
    (microsoft.public.excel.programming)
  • Re: Trying to get info and control a "child" web page
    ... Sub getgoogle() ... window with a URL matching some kind of pattern. ... Dim objShell As Object, objShellWindows As Object, o As Object ... Which opens up a page, this page I can programically navigate and open another page ...
    (microsoft.public.excel.programming)
  • Re: Taskbar shortcut menu - adding commands.
    ... calling the RemoveMenu function for all commands up to number 7 (6 is the ... >> application's MDI window is minimized. ... > Private Sub Form_Load ... > Dim bCancel As Boolean ...
    (microsoft.public.vb.syntax)