VBA Webbrower control. Search for table

eastrand

Board Regular
Joined
Nov 27, 2013
Messages
101
Office Version
  1. 365
Platform
  1. Windows
I have a built in webBrowers in a Userform. The page I'm going to will autoforward if it has been logged into within the last 2 hours. I'm trying to check for the login table on the page and if it finds it, push the login in credentials to that page. If it can't find that table, then it must already be logged in. Currently I'm using the "If Doc.getElementById("tbxUserName").Value = "" Then" to try to see if the id value is there. but this isn't working. Does anyone know how to verify if a table or field exist on a webpage within a WebBrowser control? Any help would be appreciated.

Private Sub UserForm_Initialize()
Dim IE As Object
Dim Doc As HTMLDocument

Set IE = Me.WebBrowser1

Me.WebBrowser1.Silent = True
Me.WebBrowser1.Navigate "MedPro Mobile"

Do
DoEvents
Loop Until Me.WebBrowser1.ReadyState = READYSTATE_COMPLETE

Set Doc = IE.Document

If Doc.getElementById("tbxUserName").Value = "" Then

Doc.getElementById("tbxUserName").Value = Worksheets("Variables").Range("R2").Value
Doc.getElementById("tbxPassword").Value = Worksheets("Variables").Range("R3").Value
Doc.getElementById("btnLogin").Click

End If
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
What exactly isn't working? What is the exact error, if any?

A similar approach is to see if the Login link exists:
VBA Code:
Dim LoginLink As Object
Set LoginLink = Doc.getElementById("btnLogin")
If Not LoginLink Is Nothing Then
    'Login link exists, therefore not logged in
Else
    'Login link doesn't exist, therefore already logged in
End If
 
Upvote 0
Solution
This forum never fails me. Thanks for your help. Once again, this did the trick. Btw, I would get a runtime error 91 if the page was already logged in. This allows me to bypass that by looking for the login button first. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,844
Members
449,051
Latest member
excelquestion515

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