Tuesday, November 20, 2012

Opening a new window and Login In using Internet Explore Using MS Excel VBA

Using excel VBA you can open IE Window and login in it. Following are the details for this operation.

Opening Internet Explore through excel VBA
1)      Some references should be added as follows:- These are already available in excel
a.      Microsoft HTML Object Library
b.      Microsoft Internet Controls
c.      Microsoft Forms 2.0 Object Library

2)      Code is as follow:-
             
               Dim sURL As String
              
' set url for opening here
               sURL = " http://infoenginesol.blogspot.in/"

               Set oBrowser = New InternetExplorer
               IEBrowser.Silent = True ‘if you want to open browser in silent mode
               IEBrowser.timeout = 60 ‘optionally set timeout for loading site
               IEBrowser.navigate sURL
               IEBrowser.Visible = True
              
               ' Following code will wait till Browser is loaded
              
                              Do

                              Loop Until oBrowser.readyState = READYSTATE_COMPLETE

               ‘wait included to wait till application is completed
               Application.Wait (Now + TimeValue("0:00:20"))
              
‘ for automatically login into site. On this blog you may not login, but for other site, it can be done ;-)
‘For searching proper control use “Right Click” and then “View Source”.
‘Search for word “login” or “password”. This is the way I found it; you have to search through browser source.

               Set HTMLDoc = IEBrowser.document

               HTMLDoc.all.LOGINCtrl<Use your control>.Value = “My Login”
               HTMLDoc.all.PasswordCtrl<Use your control>.Value =  “My Password”

               HTMLDoc.all("Submit_Button").Click

Application.Wait (Now + TimeValue("0:00:50"))

‘ if you want to quit after completing operation then use following or comment it
IEBrowser.Quit

No comments:

Post a Comment