Can't remaximise IE in VBA

M

Mike NG

The code below was working for me at one point, but seems to have
stopped working now. Basically if there's an instance of IE already
running that my spreadsheet knows about, I want to latch onto it -
maximising the window if it's iconised. First time through it starts a
new session and goes to the URL no problem. Second time through
If IsIconic(.hWnd) Then
is evaluating to be TRUE, but the window won't maximise. Please can
someone suggest something that works

NB My internet client (Turnpike) hooks into Explorer and can have a web
page within the client itself, which is why I've had to experiment with
how to launch a new browser session - see comments. So, I am open to
suggestions on how to launch a new browser if one isn't already running,
but please bear that in mind

The reason I want to launch them separately is because I loop through
rows on my spreadsheet. For each row, I visit a web URL and send an
email. I carry on to the next row when I see the Window Title of the
email disappear. Having the email and web browser within the same
environment is possible, but since visiting the URL requires me to sign
in I'd rather have the web stuff at the side in IE and I won't have to
sign in each time if you get my drift

So the long and the short of it is, I think I don't have any choice in
how I start IE - I need to use the method I do. I just can't work out
why it's stopped working


Public Declare Function IsIconic Lib "user32" (ByVal hWnd As Long) _
As Long

'**************************
'* Start IE and visit URL *
'**************************
Sub GotoURL(psURL As String)

Dim bPresent As Boolean
Dim sTypeName As String
Const SW_SHOW = 9
Const SW_RESTORE = 8
Const SW_MAXIMIZE = 3


'GetObject ("",InternetExplorer.Application) will latch on to
'Turnpike is less functional than full IE
'GetObject ("",InternetExplorer) won't latch on to IE at all
'(known feature), so implement our own kind of version which
'does the same sort of thing
sTypeName = TypeName(oIE)

If sTypeName = "Nothing" Or sTypeName = "Object" Then
'Nothing means never initialised
'Object means a previous IE instance has been shut down
Set oIE = New InternetExplorer
Else
'Instance already running
bPresent = True
End If


'All this seems to be necessary too, because it seems to be
'the only way to bring iconised windows back to life because
'there is no WindowState attribute
With oIE
If bPresent Then
If IsIconic(.hWnd) Then
ShowWindow .hWnd, SW_MAXIMIZE
Else
ShowWindow .hWnd, SW_SHOW
ShowWindow .hWnd, SW_MAXIMIZE
End If
Else
ShowWindow .hWnd, SW_MAXIMIZE
End If


.Navigate psURL
End With

End Sub
 
M

Mike NG

The code below was working for me at one point, but seems to have
stopped working now. Basically if there's an instance of IE already
running that my spreadsheet knows about, I want to latch onto it -
maximising the window if it's iconised. First time through it starts a
new session and goes to the URL no problem. Second time through
If IsIconic(.hWnd) Then
is evaluating to be TRUE, but the window won't maximise. Please can
someone suggest something that works

NB My internet client (Turnpike) hooks into Explorer and can have a web
page within the client itself, which is why I've had to experiment with
how to launch a new browser session - see comments. So, I am open to
suggestions on how to launch a new browser if one isn't already running,
but please bear that in mind

The reason I want to launch them separately is because I loop through
rows on my spreadsheet. For each row, I visit a web URL and send an
email. I carry on to the next row when I see the Window Title of the
email disappear. Having the email and web browser within the same
environment is possible, but since visiting the URL requires me to sign
in I'd rather have the web stuff at the side in IE and I won't have to
sign in each time if you get my drift

So the long and the short of it is, I think I don't have any choice in
how I start IE - I need to use the method I do. I just can't work out
why it's stopped working


Public Declare Function IsIconic Lib "user32" (ByVal hWnd As Long) _
As Long

'**************************
'* Start IE and visit URL *
'**************************
Sub GotoURL(psURL As String)

Dim bPresent As Boolean
Dim sTypeName As String
Const SW_SHOW = 9
Const SW_RESTORE = 8
Const SW_MAXIMIZE = 3


'GetObject ("",InternetExplorer.Application) will latch on to
'Turnpike is less functional than full IE
'GetObject ("",InternetExplorer) won't latch on to IE at all
'(known feature), so implement our own kind of version which
'does the same sort of thing
sTypeName = TypeName(oIE)

If sTypeName = "Nothing" Or sTypeName = "Object" Then
'Nothing means never initialised
'Object means a previous IE instance has been shut down
Set oIE = New InternetExplorer
Else
'Instance already running
bPresent = True
End If


'All this seems to be necessary too, because it seems to be
'the only way to bring iconised windows back to life because
'there is no WindowState attribute
With oIE
If bPresent Then
If IsIconic(.hWnd) Then
ShowWindow .hWnd, SW_MAXIMIZE
Else
ShowWindow .hWnd, SW_SHOW
ShowWindow .hWnd, SW_MAXIMIZE
End If
Else
ShowWindow .hWnd, SW_MAXIMIZE
End If


.Navigate psURL
End With

End Sub
Sorry you need this also

Public Declare Function ShowWindow Lib "user32" (ByVal hWnd As _
Long, ByVal nCmdShow As Long) As Long

It doesn't work if IE is not iconic either - i.e. I just bring something
else to the foreground.

This "not working" issue probably coincides with me upgrading from XL97
to XL2000 (with SR1a applied)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top