VBA code won't enter information in Popup Username and Password

Mjrein

New Member
Joined
Jun 19, 2017
Messages
1
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!

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!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,224,755
Messages
6,180,751
Members
452,996
Latest member
nelsonsix66

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