Connecting Tech Pros Worldwide Forums | Help | Site Map

iexplorer will not close using vba

Ronny Sigo
Guest
 
Posts: n/a
#1: Nov 13 '05
Hello all,
Below is a testroutine. I am trying to open and cclose iexplore
programmatically (the default startpage is suffcient, no need to specify
another) The opening works, but the closing does not ... can anybody tell me
what I am doing wrong?
Many thanks,
Ronny Sigo

Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) As Long
Private Const WM_CLOSE = &H10
Private lIExplorerhWnd As Long

Private Sub Knop0_Click()
Call Shell("C:\Program Files\Internet Explorer\iexplore.exe",
vbNormalFocus)
DoEvents
lIExplorerhWnd = GetForegroundWindow

Dim teller As Long
teller = 0
Do While teller < 1000000
teller = teller + 1
Loop
Call SendMessage(lIExplorerhWnd, WM_CLOSE, 0, 0)
End Sub





Tom van Stiphout
Guest
 
Posts: n/a
#2: Nov 13 '05

re: iexplorer will not close using vba


On Thu, 2 Sep 2004 11:05:47 +0200, "Ronny Sigo" <ronnysiigo@skynet.be>
wrote:

I think the reason is that GetForegroundWindow gets the foreground
window of the process the code is executing in, not of all the windows
on the desktop.
In your previous thread I posted a more promising solution.

BTW, if you MUST have a wait loop, put DoEvents or the Sleep API
inside the loop. Much better is to start a timer at the point where
you want to wait, and to close IE when that timer ticks.

-Tom.

[color=blue]
>Hello all,
>Below is a testroutine. I am trying to open and cclose iexplore
>programmatically (the default startpage is suffcient, no need to specify
>another) The opening works, but the closing does not ... can anybody tell me
>what I am doing wrong?
>Many thanks,
>Ronny Sigo
>
>Private Declare Function GetForegroundWindow Lib "user32" () As Long
>Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
>(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
>Any) As Long
>Private Const WM_CLOSE = &H10
>Private lIExplorerhWnd As Long
>
>Private Sub Knop0_Click()
> Call Shell("C:\Program Files\Internet Explorer\iexplore.exe",
>vbNormalFocus)
> DoEvents
> lIExplorerhWnd = GetForegroundWindow
>
> Dim teller As Long
> teller = 0
> Do While teller < 1000000
> teller = teller + 1
> Loop
> Call SendMessage(lIExplorerhWnd, WM_CLOSE, 0, 0)
>End Sub
>[/color]

Ronny Sigo
Guest
 
Posts: n/a
#3: Nov 13 '05

re: iexplorer will not close using vba


Hello Tom,
Thank you again, I indeed now used the Timer and it is much better ... but
.....
I try to open and close a page in a loop (when timer ticks) the problem is
that it won't close ...
can you see what I am doing wrong? I'll paste the code here ...
Thanks !
Ronny

Declarations:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As
Long
Public Const WM_CLOSE = &H82
Public lIExplorerhWnd As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long


Private Sub Form_Timer()
Call Shell("C:\Program Files\Internet Explorer\iexplore.exe",
vbMinimizedNoFocus)
DoEvents
Me!txtNumberOfTimes.Value = Me!txtNumberOfTimes.Value + 1
Me!Temphits.Value = Me!Temphits.Value + 1
IIExplorerhWnd = FindWindow("IEFrame", "Mimron's Home Page - Microsoft
Internet Explorer")
Debug.Print IIExplorerhWnd 'only to see if it gets the handle, shall be
removed afterwards ...
Call SendMessage(lIExplorerhWnd, WM_CLOSE, 0, 0)
End Sub


"Tom van Stiphout" <no.spam.tom7744@cox.net> schreef in bericht
news:b7bej0dqe3d3o0h3ntjcc57h1mvlktd532@4ax.com...[color=blue]
> On Thu, 2 Sep 2004 11:05:47 +0200, "Ronny Sigo" <ronnysiigo@skynet.be>
> wrote:
>
> I think the reason is that GetForegroundWindow gets the foreground
> window of the process the code is executing in, not of all the windows
> on the desktop.
> In your previous thread I posted a more promising solution.
>
> BTW, if you MUST have a wait loop, put DoEvents or the Sleep API
> inside the loop. Much better is to start a timer at the point where
> you want to wait, and to close IE when that timer ticks.
>
> -Tom.
>
>[color=green]
> >Hello all,
> >Below is a testroutine. I am trying to open and cclose iexplore
> >programmatically (the default startpage is suffcient, no need to specify
> >another) The opening works, but the closing does not ... can anybody tell[/color][/color]
me[color=blue][color=green]
> >what I am doing wrong?
> >Many thanks,
> >Ronny Sigo
> >
> >Private Declare Function GetForegroundWindow Lib "user32" () As Long
> >Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
> >(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
> >Any) As Long
> >Private Const WM_CLOSE = &H10
> >Private lIExplorerhWnd As Long
> >
> >Private Sub Knop0_Click()
> > Call Shell("C:\Program Files\Internet Explorer\iexplore.exe",
> >vbNormalFocus)
> > DoEvents
> > lIExplorerhWnd = GetForegroundWindow
> >
> > Dim teller As Long
> > teller = 0
> > Do While teller < 1000000
> > teller = teller + 1
> > Loop
> > Call SendMessage(lIExplorerhWnd, WM_CLOSE, 0, 0)
> >End Sub
> >[/color]
>[/color]


pj
Guest
 
Posts: n/a
#4: Nov 13 '05

re: iexplorer will not close using vba


Why not use the IE ActiveX control in Access. A tabbed form allowing
multiple sites?
pj
"Tom van Stiphout" <no.spam.tom7744@cox.net> wrote in message
news:b7bej0dqe3d3o0h3ntjcc57h1mvlktd532@4ax.com...[color=blue]
> On Thu, 2 Sep 2004 11:05:47 +0200, "Ronny Sigo" <ronnysiigo@skynet.be>
> wrote:
>
> I think the reason is that GetForegroundWindow gets the foreground
> window of the process the code is executing in, not of all the windows
> on the desktop.
> In your previous thread I posted a more promising solution.
>
> BTW, if you MUST have a wait loop, put DoEvents or the Sleep API
> inside the loop. Much better is to start a timer at the point where
> you want to wait, and to close IE when that timer ticks.
>
> -Tom.
>
>[color=green]
> >Hello all,
> >Below is a testroutine. I am trying to open and cclose iexplore
> >programmatically (the default startpage is suffcient, no need to specify
> >another) The opening works, but the closing does not ... can anybody tell[/color][/color]
me[color=blue][color=green]
> >what I am doing wrong?
> >Many thanks,
> >Ronny Sigo
> >
> >Private Declare Function GetForegroundWindow Lib "user32" () As Long
> >Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
> >(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
> >Any) As Long
> >Private Const WM_CLOSE = &H10
> >Private lIExplorerhWnd As Long
> >
> >Private Sub Knop0_Click()
> > Call Shell("C:\Program Files\Internet Explorer\iexplore.exe",
> >vbNormalFocus)
> > DoEvents
> > lIExplorerhWnd = GetForegroundWindow
> >
> > Dim teller As Long
> > teller = 0
> > Do While teller < 1000000
> > teller = teller + 1
> > Loop
> > Call SendMessage(lIExplorerhWnd, WM_CLOSE, 0, 0)
> >End Sub
> >[/color]
>[/color]


Trevor Best
Guest
 
Posts: n/a
#5: Nov 13 '05

re: iexplorer will not close using vba


pj wrote:[color=blue][color=green]
>>On Thu, 2 Sep 2004 11:05:47 +0200, "Ronny Sigo" <ronnysiigo@skynet.be>
>>wrote:
>>
>>BTW, if you MUST have a wait loop, put DoEvents or the Sleep API
>>inside the loop. Much better is to start a timer at the point where
>>you want to wait, and to close IE when that timer ticks.[/color][/color]

Use DoEvents or both, the sleep API alone won't allow Access to receive
messages and thus will appear as "not responding".


--
This sig left intentionally blank
Closed Thread