Home > Forum Home > Analyzing Corporate Financial Data > Macro that will automatically log me into web application Share

Macro that will automatically log me into web application

Excel Help for Macro That Will Automatically Log Me Into Web Application in Analyzing Corporate Financial Data


Forum TopicPost Reply Login

Macro That Will Automatically Log Me Into Web Application

Rate this:
(1.8/5 from 4 votes)
ConfusedI have a spreadsheet with links to various web based applications that I use on a dailly basis, I would like to create a macro that will auto populate the username and password and also automatically log me in.  It is not life and death but it would be nice if this was possible. I have been able to get it to populate the username and pasword fields but I still have manually click the submit/login button.  Please help as I am now pulling my hair out(not that I had much in the first place).
 Posted by on
 
Replies - Displaying 1 to 5 of 5Order Replies By: Most recent | Chronological | Highest Rated
Oops
Rate this:
(2/5 from 2 votes)
Try to either declare the constants as Public or remove Option Explicit at the top of the module.
 Excel Business Forums Administrator
 Posted by on
Confused
Rate this:
(2.5/5 from 2 votes)
tried your idea but it did not like your constants, stated that i have to declare them. 

Sub Login_WebQuery()
Dim MyPost As String
Const MyUrl As String = "https://www.btwholesale.com/siteminderagent/forms/login.fcc"
Const PostUser As String = "USER=" & Worksheets("Login Data").Range("C5").Value
Const PostPassword As String = "&PASSWORD=" & Worksheets("Login Data").Range("D5").Value
   
MyPost = PostUser & PostPassword
   
With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;" & MyUrl, Destination:=Cells(1, 1))
    .PostText = MyPost
    .BackgroundQuery = True
    .TablesOnlyFromHTML = True
    .Refresh BackgroundQuery:=False
    .SaveData = True
End With
   
End Sub
 Posted by on
Sad
Rate this:
(3/5 from 2 votes)
Instead of initiating and using the IE object, why not try using a simple web query instead.  The following code may work.

VBA Code:
Sub Login_WebQuery()
Dim MyPost As String
Const MyUrl As String = "https://www.btwholesale.com/siteminderagent/forms/login.fcc"
Const PostUser As String = "USER=" & Worksheets("Login Data").Range("C5").Value
Const PostPassword As String = "&PASSWORD=" & Worksheets("Login Data").Range("D5").Value
   
MyPost = PostUser & PostPassword
   
With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;" & MyUrl, Destination:=Cells(1, 1))
    .PostText = MyPost
    .BackgroundQuery = True
    .TablesOnlyFromHTML = True
    .Refresh BackgroundQuery:=False
    .SaveData = True
End With
   
End Sub
 Excel Business Forums Administrator
 Posted by on
Confused
Rate this:
(3/5 from 2 votes)
this is what I have, it populates the username and password fine but it will not log in.

VBA Code:
Public Sub Eco()
    Const strURL_c As String = "[http://www.btwholesale.com/]"
    Dim objIE As SHDocVw.InternetExplorer
    Dim ieDoc As MSHTML.HTMLDocument
    Dim tbxPwdFld As MSHTML.HTMLInputElement
    Dim tbxUsrFld As MSHTML.HTMLInputElement
    Dim btnSubmit As MSHTML.HTMLInputElement
    On Error GoTo Err_Hnd
     'Create Internet Explorer Object
    Set objIE = New SHDocVw.InternetExplorer
     'Navigate the URL
    objIE.navigate strURL_c
     'Wait for page to load
    Do Until objIE.readyState = READYSTATE_COMPLETE: Loop
         'Get document object
        Set ieDoc = objIE.document
         'Get username/password fields and submit button.
        Set tbxUsrFld = ieDoc.all.Item("USER")
        Set tbxPwdFld = ieDoc.all.Item("PASSWORD")
        Set btnSubmit = ieDoc.all.Item("LOGIN")
         'Fill Fields
        tbxUsrFld.Value = Worksheets("Login Data").Range("C5").Value
        tbxPwdFld.Value = Worksheets("Login Data").Range("D5").Value
         'Click submit
        btnSubmit.Click
         'Wait for page to load
        Do Until objIE.readyState = READYSTATE_COMPLETE: Loop
Err_Hnd: '(Fail gracefully)
            objIE.Visible = True
        End Sub
 Posted by on
Happy
Rate this:
(3.5/5 from 2 votes)
Yes, you can log in to the web application with a VBA macro.  You need to know the form variable names required by the login destination URL and then populate the PostText property of the web query.  There is already post on this with example VBA code here.
 Excel Business Forums Administrator
 Posted by on
 Displaying page 1 of 1 

Find relevant Excel templates and add-ins for Macro that will automatically log me into web application in the