VBA check for login in internet explorer

bluecat1254

New Member
Joined
Jul 28, 2011
Messages
7
Hello, I managed to figure out how to input login information and click the submit button on a login page but I was wondering if I could have vba check internet explorer if the login page has opened (if I had previously logged in the login page should not occur). I have something akin to the code below

Code:
With objIE
            .Navigate "url"         
            .Visible = True
 
 
            If (*WHAT CAN I TEST FOR TO SEE IF PAGE IS THE LOGIN PAGE)  Then
            Do While .Busy: DoEvents: Loop
            Do While .ReadyState <> 4: DoEvents: Loop
            .document.getelementbyid("txtusername").Value = "user"
            .document.getelementbyid("txtpassword").Value = "pass"
            'login
            .document.getelementbyid("btnlogin").Click

To elaborate, is there a command that say checks the title of the page for "account login", how would I go about this. I appreciate any help. Thank you
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Worked great thanks, although I am having a bit of difficulty extracting the content of a table into excel from internet explorer. I know the name of the table but I simply find out the appropriate command to transfer the contents of the table into excel cells (I am not using excels web query browser). Is there a particular command for getting contents from a table (like for example getelementsbyid().innertext?)
 
Upvote 0
I have something akin to this (I want to extract the table/first row of the table to the worksheet)

Dim ieTbl As Object
Set ieTbl = objIE.document.GetElementbyID("Table")
Worksheets("sheet1").Range("A1").Value = ieTbl.Rows(1).innertext

What am I doing wrong? Thanks in Advance
 
Upvote 0
I have something akin to this (I want to extract the table/first row of the table to the worksheet)
Code:
Dim ieTbl As Object
Set ieTbl = objIE.document.GetElementbyID("Table")
Worksheets("sheet1").Range("A1").Value = ieTbl.Rows(1).innertext
Is the table's Id really "Table"? That seems a bit generic for the id attribute. Also, the first row is Rows(0), not Rows(1).

As a beginner, you'll struggle to develop code to parse HTML elements with late binding (Dim ieTbl As Object). It's far easier to set a reference to the Microsoft HTML Object Library in Tools - References, and declare variables as the appropriate class. With this, the code changes to something like this (assuming "Table" is the correct Id for the table you want to reference):
Code:
    Dim table As HTMLTable
    Dim tableCell As HTMLTableCell
    
    Set table = objIE.document.GetElementbyID("Table")

    For Each tableCell In table.Rows(0).Cells
        Worksheets("Sheet1").Range("A1").Offset(0, tableCell.cellIndex).Value = tableCell.innerText
    Next
 
Upvote 0
Thank you for the response and advice, I am beginning to solve my issues. I hate to persist but I have a final question. If an html table doesn't have an id, do I have to loop through all of the tables on the page to find the particular one I am looking for?
 
Upvote 0
It all depends on the specific HTML. Yes, you could loop through all the tables looking for something e.g. text, or an attribute value, etc. which distinguishes the table you want. Or if the table always has the same element index you could do this:

Code:
'Get 5th table
Set table = objIE.document.getElementsByTagName("TABLE")(4)
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,424
Members
452,914
Latest member
echoix

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