Open Current Webpage with VBA

taraus88

New Member
Joined
Apr 8, 2006
Messages
18
I have created a UserForm which consist of Textbox’s and Commandbutton’s . For one Textbox, it’s purpose is for entering account number information such as: 100200300. After entering the account number in the Textbox, I wont it to then be inserted into a Webpage HTMLInputBox. Then by clicking on the Commandbutton, I would like for it to access the account from the webpage. Now I have created a code to do this but the only problem, I don’t want the code to create a new webpage. Instead, I would like the code to select the existing webpage or document that I already have opened. Lets use the web page for Yahoo Mail as an example for the code. https://login.yahoo.com/config/login_verify2?.intl=us&.src=ym. This page consist of a Yahoo ID, Password, CheckBox, then a Sign In Button. The Yahoo page source code.

For the HTMLInputBox, "input name='login' id='username' maxlength='96' tabindex='1' value=''"
For the next HTMLInputBox, "input name='passwd' id='passwd' type='password' maxlength='64' tabindex='2'"
For the Submit Button, "button type='submit' id='.save' name='.save' class='secondaryCta' tabindex='5'"

Here’s the code I’m currently using. Remember, I’m not looking to create at new webpage but to access the current webpage I’ve currently pulled up.

Private Sub CommandButton8_Click()

Const cURL = “https://login.yahoo.com/config/login_verify2?.intl=us&.src=ym”

Dim IE As Object
Dim doc As HTMLDocument
Dim LoginForm As HTMLFormElement
Dim UserNameInputBox As HTMLInputElement
Dim SignInButton As HTMLInputButtonElement
Dim HTMLelement As IHTMLElement

Set IE = CreateOject(“InternetExplorer.Application”)

IE.Visible = True
IE.navigate cURL

'Wait for initial page to load

Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

Set doc = IE.document

'Get the only form on the page

Set LoginForm = doc.forms(0)

Set UserNameInputBox = LoginForm.elements("username")
UserNameInputBox.Value = TextBox17.Text

Set SignInButton = LoginForm.elements(".save")
SignInButton.Click

'Wait for the new page to load

Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

'Get the HTML document of the new page

Set doc = IE.document

End Sub
 

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