Using URL address from Excel

yosi

Board Regular
Joined
May 14, 2002
Messages
67
the code that allow me to open a web site from excel is -
ActiveWorkbook.FollowHyperlink Address:="http://www.mrexcel.com", NewWindow:=True

the problem - if the web site is open how to activate the window and not open a new window

changing true to false at the end of the code does not do the job
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hello Yosi,

We can grab a handle on the Internet Explorer to test whether it's open or not:<pre>
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Sub test()
Dim h As Long, IntEx As Object
h = FindWindow("ieframe", vbNullString)
If h > 0 Then
Set IntEx = _
GetObject(, "InternetExplorer.application")
IntEx.Visible = True
IntEx.Navigate "http://www.mrexcel.com"
Else: Set IntEx = CreateObject("WScript.Shell")
IntEx.Run "IExplore.exe http://www.MrExcel.com"
End If
End Sub</pre>

Edit: Depends what you by web site is open. If you meant that you I.E. is open, but if it's not on the MrExcel url, then open a new window, try:<pre>
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Option Compare Text
Sub test()
Dim h As Long, IntEx As Object
h = FindWindow("ieframe", vbNullString)
If h > 0 Then
Set IntEx = GetObject(, "InternetExplorer.application")
If InStr(IntEx.Document.url, "mrexcel.com") Then
IntEx.Visible = True
IntEx.navigate "http://www.mrexcel.com"
Exit Sub
Else: GoTo 1
End If
Else:
1: Set IntEx = CreateObject("WScript.Shell")
IntEx.Run "IExplore.exe http://www.mrexcel.com"
End If
End Sub</pre>

But this doesn't loop through windows, it'll grab the first instance.

Hope this helps.

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue"> Oliver</font></font></font>
This message was edited by NateO on 2002-12-16 03:15
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top