PC Review


Reply
Thread Tools Rate Thread

Access popup window from IE object.

 
 
=?Utf-8?B?TWF5aGV3?=
Guest
Posts: n/a
 
      19th Oct 2006
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
 
Reply With Quote
 
 
 
 
Tim Williams
Guest
Posts: n/a
 
      19th Oct 2006
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" <(E-Mail Removed)> wrote in message news:7EA2D8FB-9119-4808-AC43-(E-Mail Removed)...
> 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



 
Reply With Quote
 
=?Utf-8?B?TWF5aGV3?=
Guest
Posts: n/a
 
      19th Oct 2006
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" <(E-Mail Removed)> wrote in message news:7EA2D8FB-9119-4808-AC43-(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
Tim Williams
Guest
Posts: n/a
 
      20th Oct 2006
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" <(E-Mail Removed)> wrote in message
news:A59EF4A3-421E-4658-8A50-(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
>> news:7EA2D8FB-9119-4808-AC43-(E-Mail Removed)...
>> > 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

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?TWF5aGV3?=
Guest
Posts: n/a
 
      20th Oct 2006
That worked great. Thanks a bunch!

"Tim Williams" wrote:

> 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" <(E-Mail Removed)> wrote in message
> news:A59EF4A3-421E-4658-8A50-(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> >> news:7EA2D8FB-9119-4808-AC43-(E-Mail Removed)...
> >> > 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
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access 2000. Cant see object window =?Utf-8?B?RmV6ejE5NTQ=?= Microsoft Access 2 22nd Aug 2009 12:44 AM
launch access report in popup window mg Microsoft Access Forms 2 11th Feb 2009 07:24 PM
Popup Window for someone trying to access e-mail addresses. =?Utf-8?B?Q3VydCBIYW5k?= Microsoft Outlook Discussion 10 12th Sep 2006 12:53 AM
popup window bug - popup window is covered with drop-list arrows =?Utf-8?B?TWlrZSBSb2JlcnRz?= Windows XP Internet Explorer 1 21st May 2006 02:09 PM
How to connect to host with no popup window to confirm access? Joachim Windows XP Work Remotely 0 16th Oct 2003 08:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:42 PM.