Automating an already open Internet explorer Window

ftv

Board Regular
Joined
Sep 27, 2010
Messages
74
Hey guys , i need a little assistance trying to figure out how i can run a code in an already existing internet explorer window

ive seen several codes but i cant seem to get them to work. im using 2003


the code i have seen is but i just cant get anything to work
For Each ie As InternetExplorer In New ShellWindows
If ie.LocationURL = www.google.com Then
ie.Navigate ("www.google.com")
MessageBox.Show (ie.Path.ToString)
End If


after i complete that task ,i need to next figure out how to fill in a form with a single cell from my spreadsheet
 
As far as I can see that HTML isn't for a form.

Also the script appears to be for doing something with some sort of toolbar.

One more thing, I think it might have been automatically generated.

The reason I think that is because of the use of some sort of session ID.

Those are usually unique and generated on sites for security reasons.

Is that why you can't post the URL?
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I cant post it because i would probly get in trouble for doing so, im just trying to make my daily tasks easier ... idk if this helps but i found this source code for the tool that already does it just not with excel data. its different from the one i put in before
HTML:
< script type="text/javascript" src=" common/JavaScript/****JavaScriptUtil.js" >< / script  >
< script type= "text/javascript" src=" common/JavaScript/titleBar.js">*********>
< script type="t ext/javascript">
var origDomain = document.domain
var domainSuffix = origDomain.substring(origDomain.indexOf('.')+1)
var autoDocText = "";
function getActiveText(e) { 
// Sets text MSIE or Netscape active 
// text based on browser, puts text in form
// Only update autoDocText selection if the selection is
autoDocText = (document.all) ? docContent.document.selection.createRange().text : docContent.document.getSelection();
//alert('highlighted = ' + autoDocText)
return true;
}
 
Upvote 0
I'm afraid the JavaScript isn't really relevant.

The syntax and context of use are quite different from how you would approach this in VBA.

Why do you need this for an already open IE window anyway?

The code you've posted for 'grabbing' that might not actually be picking up the right window.

Without the URL I'm afraid it's pretty hard to help - the HTML can be useful but seeing it out of context it doesn't always make sense.

One thing I think you should try looking into would be to use GetElemenytByID to get references for the form and it's input elements eg textboxes.

In the last HTML code you posted I'm sure I saw IDs for a couple of things.:)
 
Upvote 0
well, its an intranet site so you couldnt get into it anyway , the reason i need to do it with an open internet explorer window is ... let me just explain my job a little bit, i work at a call center where i answer customers questions and we use a web based system as our main system we use to take calls, and on the bottom of the internet explorer window that i have open to take my calls is the area for free form documentation. I have to document every call with what the customer is calling about. I have a spreadsheet where i have common things i use for documentation like, "customer is calling about Phone number for such and such, gave #" just other stuff like that. With this sheet i can document more than three quarters of my calls,im just trying to make tasks simpler. so instead of copying the cell in my sheet with what i want to document the call with, i just run the macro quick and it will grab it and paste it into the internet explorer window that my system is in, since i obviously have to have it open all day to take my calls
 
Upvote 0
The Get_IE_Window function below looks for an IE window or tab already open at a specific URL and IE_Window_Test shows how to call it. It uses early binding, so the VBA project needs a reference to MS Internet Controls, but is easily converted to late binding instead.
Code:
Public Sub IE_Window_Test()
  
    Dim URL As String
    Dim IE As InternetExplorer
    Dim IEopened As Boolean
    Dim response As Variant
    
    URL = "http://www.mrexcel.com/forum/forumdisplay.php?f=10"
    URL = "www.mrexcel.com/forum/forumdisplay.php?f=10"
    
    IEopened = False
    Set IE = Get_IE_Window(URL)
    If IE Is Nothing Then
        Set IE = New InternetExplorer
        IEopened = True
    End If
    
    With IE
        .Visible = True
        .Navigate URL
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        While .Document.readyState <> "complete": DoEvents: Wend
        
        Debug.Print .LocationURL
    End With
    
    If IEopened Then
        response = MsgBox("Close the newly opened Internet Explorer window?", vbYesNo)
        If response = vbYes Then IE.Quit
    End If
    
End Sub


Private Function Get_IE_Window(URL As String, Optional Protocol As String = "http://") As InternetExplorer

    'Look for an IE browser window or tab already open at the address (protocol+domain) of the specified URL and, if found, return
    'that browser as an InternetExplorer object.  Otherwise return Nothing

    Dim address As String
    Dim Shell As Object
    Dim IE As Object
    Dim i As Variant 'Integer
    
    If Left(URL, Len(Protocol)) <> Protocol Then URL = Protocol & URL
    address = Left(URL, InStr(Len(Protocol) + 1, URL, "/") - 1)

    Set Shell = CreateObject("Shell.Application")
    
    i = 0
    Set Get_IE_Window = Nothing
    While i < Shell.Windows.Count And Get_IE_Window Is Nothing
        Set IE = Shell.Windows.Item(i)
        If Not IE Is Nothing Then
            If TypeName(IE.Document) = "HTMLDocument" Then
                Debug.Print IE.LocationURL
                If InStr(IE.LocationURL, address) > 0 Then
                    Set Get_IE_Window = IE
                End If
            End If
        End If
        i = i + 1
    Wend
    
End Function
If your web site uses the secure (https) protocol, then call it using:

Set IE = Get_IE_Window(URL, "https://")

One caveat is that if an IE window or tab is found for the specified URL, it will always use the active tab, which may not be the same tab that your web site is opened in.
 
Upvote 0

Forum statistics

Threads
1,224,620
Messages
6,179,925
Members
452,949
Latest member
beartooth91

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