Hey Everyone! This is my first post on here and I really need help. I'm not a programmer at all, in fact I just started using VBA yesterday. I'm trying to code in VBA to access the trademap.org website data. The problem first is that I need to get through the authentication. My code works upto the point that it goes to the website, clicks the login, and it generates the popup, but it refuses to enter the Username and password, and I have tried everything! Please help!
Alternatively, I have also tried this and it does not work and I do not understand why:
Thank you!
Code:
Sub Test()
'Declaring the necessary variables.
Dim IE As Object
Dim IEPage As Object
Dim IEPageElement As Object
'Create a new Internet Explorer instance, make it visible and maximize its window.
On Error Resume Next
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
'Check if the object was created.
If Err.Number <> 0 Then
MsgBox "Sorry, it was impossible to start Internet Explorer!", vbCritical, "Internet Explorer Error"
Exit Sub
End If
'Navigate to the requested URL.
IE.navigate ("http://www.trademap.org/Index.aspx")
'Wait until the web page is fully loaded.
Do Until IE.readyState = 4 'READYSTATE_COMPLETE in early binding
DoEvents
Loop
'Get the document of the URL.
Set IEPage = IE.Document
'Find the Sign-In button using the element ID.
Set IEPageElement = IEPage.getElementById("ctl00_MenuControl_Label_Login")
If Not IEPageElement Is Nothing Then
'Click Login
IEPageElement.Click
Set IEPageElement = Nothing
End If
Set IEPageElement = IEPage.getElementById("ctl00_PageContent_Login1_UserName")
If Not IEPageElement Is Nothing Then
'Pass the UserName value
IEPageElement.Value = "xxxx"
Set IEPageElement = Nothing
End If
Set IEPageElement = IEPage.getElementById("ctl00_PageContent_Login1_Password")
If Not IEPageElement Is Nothing Then
'Pass the Password value
IEPageElement.Value = "xxxx"
Set IEPageElement = Nothing
End If
IE.document.all("ctl00_PageContent_Login1_Button").Click
'Release the objects.
Set IEPageElement = Nothing
Set IEPage = Nothing
Set IE = Nothing
End Sub
Alternatively, I have also tried this and it does not work and I do not understand why:
Code:
IE.Document.getElementById("ctl00_PageContent_Login1_Username").Value = "xxxx"
IE.Document.getElementById("ctl00_PageContent_Login1_Password").Value = "xxxx"<strike></strike>
Thank you!