VBA – Connect to a Web Page

Spread the love

Access Web Page by VBA

copy below code and try

Public Const mySheet = “sheet1”

‘Enable reference for html and internet

‘ GOTO > TOOLS > REFERENCE >
‘ MICROSOFT HTML OBJECT LIBRARY
‘ MICROSOFT INTERNET CONTROLS
Sub WebAccess()

Dim htmdoc As HTMLDocument
Dim ie As InternetExplorer
Dim STARTROW, LROW As Integer

Set W_LINK = Worksheets(mySheet)
Set ie = New InternetExplorer

STARTROW = 2
LROW = W_LINK.Range(“A1048576”).End(xlUp).Row

                   Do While ie.Busy
Application.Wait DateAdd(“s”, 1, Now)
Loop

For I = STARTROW To LROW
‘refrence to a sheet
‘S_Val = W_LINK.Range(“A” & I).Value

S_Val = “http://excelinhindi.com/register/”
ie.navigate S_Val
ie.Visible = True

Do While ie.Busy Or ie.readyState <> 4
DoEvents

Loop

Set htmdoc = ie.document

htmdoc.getElementById(“signup_username”).Value = Application.UserName
htmdoc.getElementById(“field_1”).Value = Application.UserName & “cool”

Next I

End Sub