How to Send a Username & Password to a Website With Excel VBA Code

Written by darrin koltow
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Send a Username & Password to a Website With Excel VBA Code
( Images)

Excel's programming language, Visual Basic for Applications (VBA), lets Microsoft Office programmers extend the abilities that ship with Excel. One example of this extension is a VBA program that can enter login information on a web page, and then submit that information. This model is a hierarchy of virtual objects that comprise Excel's programmable features. Sending a user name and password to a website with VBA saves your program's user from the inconvenience of entering this information manually.

Skill level:


  1. 1

    Open Excel, then display the VBA coding window by pressing "Alt-F11."

  2. 2

    Double-click the item displaying "This workbook" in the navigation pane at screen left. This opens a window for entering code for the current workbook.

  3. 3

    Type or paste the following program into the window that appears. This program calls the VBA statement "AppActivate" to direct input from the current application, Excel, to your browser. The "SendKeys" statement sends keystrokes, the login and password information, to the activated browser. The text "{TAB}" and "~" represent the "Tab" and "Enter" keys. The statement Application tells Excel to pause briefly to allow Windows and your browser time to process the keystrokes sent to it.

    Public Sub send Password()

    AppActivate "BROWSER_NAME", True

    SendKeys "YOUR_LOGIN_ID", True

    Application.Wait 1000

    SendKeys "{TAB}", True

    SendKeys "YOUR_PASSWORD", True

    Application.Wait 1000

    SendKeys "~", True

    End Sub

  4. 4

    Replace the text "BROWSER_NAME" with the name of the browser (for example, "Firefox," "Internet Explorer," and "Google Chrome") you'll use to login to the web page. Replace the text "YOUR_LOGIN_ID," and "YOUR_PASSWORD" with the login information the web page requests.

  5. 5

    Open the web page you'd like your code to log into.

  6. 6

    Click one of the statements of the "sendPassword" subroutine, then press "F5" to run that subroutine. Windows will restore focus to the browser your program has activated. Your program will type and then send the login information you encoded in it.

  7. 7

    Paste the following revision to the first program below that program in the VBA development window. This version of "sendPassword" will enter login information not from code, but from values on a worksheet in the current workbook. The main advantage of this approach is the convenience of changing the login information. Data stored in a worksheet is more convenient to change than it is to program code.

    Public Sub sendPasswordStoredInWorksheet()

    Dim login, pword, app

    app = ActiveSheet.Cells(1, 1).Value

    login = ActiveSheet.Cells(2, 1).Value

    pword = ActiveSheet.Cells(3, 1).Value

    AppActivate app, True

    SendKeys login, True

    Application.Wait 1000

    SendKeys "{TAB}", True

    SendKeys pword, True

    Application.Wait 1000

    SendKeys "~", True

    End Sub

  8. 8

    Type the browser name and login information you coded into the first version of the program in the top three cells of the Excel workbook's first worksheet.

  9. 9

    Log out, in your browser, from the website your first program logged into, then return to the site's login page. Run the new version of the program, using instructions from step 6. The login will commence as it did in step 6.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.