• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Excel VBA Website Login

ashwinchopra

New Member
Hi All,
I am trying to login to a web page with the help of VBA. But the code isnt working. It take me to the web page but after that it doesnt enters the login credentials. Kindly help
Thanks in Advance


Code:
Dim HTMLDoc As HTMLDocument

Dim MyBrowser As InternetExplorer

Sub GST()





Dim MyHTML_Element As IHTMLElement

Dim MyURL As String

On Error GoTo Err_Clear

MyURL = "https://services.gst.gov.in/services/login"

Set MyBrowser = New InternetExplorer

MyBrowser.Silent = True

MyBrowser.navigate MyURL

MyBrowser.Visible = True

Do

Loop Until MyBrowser.readyState = READYSTATE_COMPLETE

Set HTMLDoc = MyBrowser.document

HTMLDoc.all.user_name.Value = "abccccc" 'Enter your email id here

HTMLDoc.all.user_pass.Value = "abcdds1" 'Enter your password here

For Each MyHTML_Element In HTMLDoc.getElementsByTagName(“input”)

If MyHTML_Element.Type = “submit” Then MyHTML_Element.Click: Exit For

Next

Err_Clear:

If Err <> 0 Then

Err.Clear

Resume Next

End If

End Sub
 
Last edited by a moderator:
Hi All,
I am trying to login to a web page with the help of VBA. But the code isnt working. It take me to the web page but after that it doesnt enters the login credentials. Kindly help
Thanks in Advance


May i reason for the GST website login from VBA, There are plenty of software which offers filling directly from the software via API call and scrapping the said website is illegal as well. There's also captcha, so you can't login in the same way.
 
Hi,

Pls check.

HTML:
Option Explicit

#If VBA7 Then
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
#Else
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems
#End If

Sub GSTLogin()
Dim url As String, IE As Object
url = "https://services.gst.gov.in/services/login"


With CreateObject("InternetExplorer.Application")
Sleep 500
.Visible = False
Sleep 100

.Navigate url
Do While .Busy Or .readyState <> 4: DoEvents: Loop
.Visible = True

Sleep 1000 'Increase it if failed to load due to speed.
'On Error Resume Next
  With .document
    .getElementsByName("user_name")(0).Value = 1
    .getElementsByName("user_pass")(1).Value = 2
  End With

'On Error GoTo 0

.Visible = True
End With

End Sub
 
No idea and it will not that easy as well due to both are two different vendors. You must happy with IE when dealing with VBA and web automation.
 
I'm not a fan, but there is something called Selenium extension, which can be utilized to manipulate chrome with vba.
 
Hi,

Pls check.

HTML:
Option Explicit

#If VBA7 Then
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
#Else
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems
#End If

Sub GSTLogin()
Dim url As String, IE As Object
url = "https://services.gst.gov.in/services/login"


With CreateObject("InternetExplorer.Application")
Sleep 500
.Visible = False
Sleep 100

.Navigate url
Do While .Busy Or .readyState <> 4: DoEvents: Loop
.Visible = True

Sleep 1000 'Increase it if failed to load due to speed.
'On Error Resume Next
  With .document
    .getElementsByName("user_name")(0).Value = 1
    .getElementsByName("user_pass")(1).Value = 2
  End With

'On Error GoTo 0

.Visible = True
End With

End Sub


But this code does not activate captcha code automatically, we need to edit username to get the captcha code.
 
spymate420
You should reread Forum Rules:
Start a new post every time you ask a question, even if the theme is similar.
 
Back
Top