Solved

.Navigate URL in current IE windows or object in VBA

Posted on 2011-02-27
14
1,743 Views
Last Modified: 2012-05-11
Dear Expert,

I  am going through the long time process to create one IE object or window . and I plan not to quit the IE instance/window
until the computer is shut down. The current IE window will be used for other new VBA automation program. But
I don't know how to transfer the object information or property  of the current/existing IE window to the new IE object which
created from the new VBA program. I read some help that mention use shellwindow to grab the exsitng
IE window  object information and property at http://bytes.com/topic/visual-basic-net/answers/353392-how-access-current-internet-explorer-vb-net,
but it is not clear for me. Any code provide for the problem of  newIE.navigate URL on the existing IE window? please advise


Thanks

Duncan

 
0
Comment
Question by:duncanb7
  • 9
  • 5
14 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34996185
You don't need to use Shell for this. You can use CreateObject in VBA.

And once you are done simply use

Object.Quit

and then

Set Object = Nothing

See the example below.

Dim browser As Object

Private Sub IEObj()
    On Error GoTo ErrIE
    
    Set browser = CreateObject("InternetExplorer.Application")
    
    browser.Visible = True
    
    browser.Navigate ("http://koolsid.com")
    
    '~~> You can now use 'browser' object in your code
    '~~> till the time you destroy it.
    
    'browser.Quit
    'Set browser = Nothing
    
    Exit Sub
ErrIE:
    MsgBox Err.Description
End Sub

Open in new window


Sid
0
 
LVL 13

Author Comment

by:duncanb7
ID: 34996204
I mean I navigate URL on the existing or opened IE windows
0
 
LVL 13

Author Comment

by:duncanb7
ID: 34996207
I mean I navigate URL on the existing or opened IE windows  not on the new IE window or object
0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34996211
And if there is no existing or opened IE?

Sid
0
 
LVL 13

Author Comment

by:duncanb7
ID: 34996224
Actually do you understand my question, i could explan more, and I don't know your question means ?(And if there is no existing or opened IE?)
0
 
LVL 13

Author Comment

by:duncanb7
ID: 34996240
Opened IE windows means that is not opened on my working program and it might create by
other program using other lanugage  
0
 
LVL 13

Author Comment

by:duncanb7
ID: 34996271
In other words, the opened IE windows is created seperately from my program.
Probably, we might use SHDocVw.ShellWindows
 to find the target title window first before navigate URL
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34996273
Ok Correct me if I am wrong. What I understood from your query is that you have opened IE from a different program and now you want to use that IE from VBA?

If not, then yes, if you can explain more then maybe I can give you the exact solution :)

Sid
0
 
LVL 13

Author Comment

by:duncanb7
ID: 34996320
For example,

now you open example IE window  by clicking on the IE icon on desktop windows abd browser to www.yahoo.com
and the IE titlte would be Yahoo!--Windower Explorer.
and then now you use new VBA program  for navigate example URL like www.goggle.com  but you could NOT create
new IE object for browsing , you need to navigate the URL on the opened window  with the title  Yahoo!-Window
0
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 500 total points
ID: 34996334
Oh Ok.

Like this?

Sub Sample()
    Dim SW, IE
    
    Set SW = CreateObject("Shell.Application")
    For Each IE In SW.Windows
    If TypeName(IE.Document) = "HTMLDocument" Then
        If IE.LocationURL = "http://in.yahoo.com/?p=us" Then _
        IE.Navigate "www.Google.com"
    End If
    Next
End Sub

Open in new window


Sid
0
 
LVL 13

Author Comment

by:duncanb7
ID: 34996351
Yes it is correct  totally , and I found the solution yesterday from this wbesite
http://vba-corner.livejournal.com/4623.html but won't want to delete the
question. ANywaym you deserve the point
0
 
LVL 13

Author Closing Comment

by:duncanb7
ID: 34996353
Thanks you reply
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34996370
duncanb7: You are very kind but you should never do that ;)

If you have found an answer by yourself then post that here and then accept your answer and close the question. You don't need to delete it. :) This will also help other people who come searching for similar answers :)

Sid
0
 
LVL 13

Author Comment

by:duncanb7
ID: 34996399
Got it , anyway thanks for sharing
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question