i am trying to open new tabs (which i can) and then close one of them (let's say the 2nd tab out of 5)
and another question is how can i get the document of that 2nd tab? 2ndTab.Document ????
would it be possible to launche new tab with some like this (i tried alot of methods did not get it to work)
Code:
Option Explicit
Private IE As Object
Private IETab As Object
Private Sub Form_Load()
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "www.google.com"
Set IETab = IE.Navigate2("www.hotmail.com", 2048)
End Sub
i know this will never work.. but how can i do this? is there a way
i would like to be able to navigate to where i want with any tab i want
you can do this, but you need to find some way to identify each tab, possibly if you get the first tab, the others will be consecutive, but i have never tested if this is the case
you can use a shell object to find ie windows then automate each window, but the index of ie windows will change if explorer windows are opened or closed, as explorer windows are always first in the shell windows collection, and of course there maybe multiple ie instances as well
note each tab is a separate shell window
Last edited by westconn1; Aug 13th, 2012 at 06:31 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
after your suggestion i have looked into it you can use either
Code:
ShDocVw.ShellWindows 'This requires reference to Microsoft Internet Controls and you can use withevents (if needed)
'or
CreateObject("Shell.Application") 'This does NOT require any reference but cannot use withevents
and code
Code:
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Private Google As Object
Private Bing As Object
Private Yahoo As Object
Private IEOpened As Boolean
Private Sub LoadSearchEngine()
Dim Shell_Windows As Object
Dim IE As Object
IEOpened = False
Set Shell_Windows = CreateObject("Shell.Application").windows
For Each IE In Shell_Windows
If IE.Application = "Windows Internet Explorer" And Not IE.locationname = vbNullString Then
IEOpened = True
List1.AddItem IE.locationname
End If
Next
If Not IEOpened Then
GoTo CreateWindows
ElseIf MsgBox("Please close all Internet Explorer windows, would you like me to close them all for you and load the search websites?", vbExclamation Or vbYesNo, "Opened Windows Found") = vbYes Then
Shell "cmd.exe /c TASKKILL /IM iexplore.exe /F"
Sleep 2000
GoTo CreateWindows
End If
Exit Sub
CreateWindows:
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "www.google.com"
IE.navigate2 "www.bing.com", 2048 '2048 create new tab
IE.navigate2 "www.yahoo.com", 2048 '2048 create new tab
Sleep 2000
For Each IE In Shell_Windows
If IE.Application = "Windows Internet Explorer" And Not IE.locationname = vbNullString Then
If InStr(1, IE.locationname, "Google") <> 0 Then
Set Google = IE
ElseIf InStr(1, IE.locationname, "Bing") <> 0 Then
Set Bing = IE
ElseIf InStr(1, IE.locationname, "Yahoo") <> 0 Then
Set Yahoo = IE
End If
End If
Next
Bing.Visible = True
Google.Visible = True
Yahoo.Visible = True
End Sub
Private Sub Command1_Click()
'Control Google tab here (navigate,document,visible,left,top,width,height ETC)
Google.navigate "www.hotmail.com"
End Sub
Private Sub Command2_Click()
'Control Bing tab here (navigate,document,visible,left,top,width,height ETC)
Bing.navigate "www.hotmail.com"
End Sub
Private Sub Command3_Click()
'Control Yahoo tab here (navigate,document,visible,left,top,width,height ETC)
Yahoo.navigate "www.hotmail.com"
End Sub
Private Sub Form_Load()
LoadSearchEngine
End Sub
@Max - I've been following this thread with interest. For the life of me I could not get the 'new tab' piece to work unless I specifically cast the '2048' as a Long (ie 2048&) in the Navigate statement. As for trying to obtain the 'Document' object from IE for each Tab - Getting the first one was simple but as for the others - I gave up eventually.
Googling around I discovered that there's an undocumented interface for handling Tabs in IE which the Guys from Chrome have (or might have) implemented.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
At doogle where is that undocumented website? I have been looking and looking never found an answer for controlling tabs but i got it to work yesturday thanks to westconn and my researches
At westconn that is exactly where i found the parameters
In the end i am happy with what i finally got working hopefully this will anwser a couple questions in the futur