By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

iexplorer will not close using vba

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Thu, 2 Sep 2004 11:05:47 +0200, "Ronny Sigo" <ro********@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.

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


Nov 13 '05 #2

P: n/a
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*************@cox.net> schreef in bericht
news:b7********************************@4ax.com...
On Thu, 2 Sep 2004 11:05:47 +0200, "Ronny Sigo" <ro********@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.

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 mewhat 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

Nov 13 '05 #3

P: n/a
pj
Why not use the IE ActiveX control in Access. A tabbed form allowing
multiple sites?
pj
"Tom van Stiphout" <no*************@cox.net> wrote in message
news:b7********************************@4ax.com...
On Thu, 2 Sep 2004 11:05:47 +0200, "Ronny Sigo" <ro********@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.

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 mewhat 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

Nov 13 '05 #4

P: n/a
pj wrote:
On Thu, 2 Sep 2004 11:05:47 +0200, "Ronny Sigo" <ro********@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.


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
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.