Microsoft Excel - Urgent help!!! Execute VBA Code on Existed Opened IE

Asked By Rajender Prasad on 16-May-13 10:42 AM

Dear All,

I am trying to automate Internet Explorer application using html tags.

As we are already aware that we have different tags for each web page which we are trying to access.

But, if am writing code in vba, I am always creating an IE object and working with it.

But, I want my code to be run on opened web page wherever I want.

Is there any way to write the code for web page without creating an object for IE. Please suggest.


Robbe Morris replied to Rajender Prasad on 16-May-13 10:44 AM
You are going to have to clarify what you are after.

Are you attempting to interact with an existing web page?  Look at its html, click buttons, fill in forms and submit them?


Do you just want to read the html stream of a web page?  If so, are you attempting to hook into a open browser session or do you just need to have VBA code that you can pass a url to and get the html from the rendered page?


Are you attempting to inject your VBScript code and execute it inside of an existing web page hosted somewhere?
Rajender Prasad replied to Robbe Morris on 16-May-13 11:10 AM
Thanks for the reply...

I have one Application where the URL will not change at all,  though you do any operations on Application ( I mean if you access any link or anything on app, URL will be same) .

As you said am filling the details using html tags in vba and submitting them.

As of now Using something like   IE.Document.getelementsbytagname("input")...etc.. after creating internet explorer object.

But, I have different different html forms, and I want to fill them using vba without creating object of IE.


I will login manually, I will go ABCD menu manually, after ABCD menu webpage is launched. I will fill the details or else I will copy the details etc..or else I will copy and paste the details to another menu from this menu..etc..

But only these operations should happen using vba code. Login and Accessing ABCD menu should be always manual work.

Hope I am lil clear now. Please help

Robbe Morris replied to Rajender Prasad on 16-May-13 11:16 AM
Gotcha.  I've done something like this to automate searches in Google for Facebook pages and then automatically "liking" pages found in the results.

I think you'll want to get away from the IE object and use the COM WebBrowser control on a VBA form instead.  This will let you interact with urls as a human and then be able to press command buttons on your VBA form to work with the DOM of the web page, click buttons, and submit results.

There are tons of code samples out there for working with the web browser control.  I imagine you'd have to add a reference to the COM control in your VBA project references.
Rajender Prasad replied to Robbe Morris on 16-May-13 11:22 AM
ok.. Thanks.. But I Meant to say that forms means, html forms not vba how can I and where can i get such type of sample code... I juct want to execute my code on opend web page.

Robbe Morris replied to Rajender Prasad on 16-May-13 11:32 AM
I know what you meant about HTML forms.  The WebBrowser control pulls up the web page in a browser control.  Like an OCX control on your VBA form.  Using VBA code in the VBA form, you can interact with the html elements on the page.  For instance, you could populate an html input textbox from VBA code running in your VBA form.  You can react to browser page events like document_complete.  You could click html buttons or submit the page.  It is similar to what you are doing with the IE object but you've got human interaction and you are running the page in the full browser context (which has access to JavaScript functions etc...)
Rajender Prasad replied to Robbe Morris on 16-May-13 11:46 AM
can u please post if you have any sample of code as am going mad with google gettong lot of unnecessary things.
I do not want to use
Set IE=createobject("InternetExplorer.Applications")
IE. navigate "http://somthing"

instead my code should directly run on already opend web page.


Robbe Morris replied to Rajender Prasad on 16-May-13 11:55 AM
Do not use this:

Set IE=createobject("InternetExplorer.Applications")
IE. navigate "http://somthing"

You drop the WebBrowser control on a VBA form after creating a reference to it in your Excel project.  Search Google for these terms:  VBA WebBrowser navigate vb 6.0

You'll get code that works in VBA and in VB 6.0.

You'll find that the WebBrowser control is now like a TextBox, ListBox, or DataGrid control on your VBA form.  You can wire up events and work with it just like any other control.  The difference is that you are interacting with the DOM of the web page currently being shown.