2

I have moderate knowldege in EXCEL VBA, but very new while createing HTML interaction with VBA.

The below code is working on a secured server(intranet). Where till login my code works perfectly and there after the issues starts,
1. It was not able to pick the element from the HTML tag.
2. After setting the buttonclick it just jump to End sub.
3. When i try to debug and try to run the skipped codes I can see error Object variable or with block variable not set (Please find the screenshot)
4. Tried Debug.Print but no value get picked

VBA Code:

Sub Weblink

    Dim IE As Object
    Dim HTMLDoc As Object
    Dim sURL As String
    UserName = (Environ$("Username"))
    cPassword = Inputbox ("Tokan Password","Password","????")
    Set IE = New InternetExplorerMedium
    sUrl = "www.ulr.com"

    With IE
        .navidate (sURL)
        .Visible = True
    End With
    Application.wait (Now + TimeValue ("0:00:05"))

    Set HTMLDoc = IE.document
    HTMLDoc.GetElementByID ("id5").value = UserName
    HTMLDoc.GetElementByID ("id6").value = cPassword

    For Each MyHtml_Element In HTMLDoc.getElement.Click: Exit For
    Next

    Set buttonClick = HTMLDoc.getElelmentsByClassName ("topmenu menu-has-submenu") 'code exicute till here
    For Each element in buttonClink              'Code wont take this line - if try to run in debugmode Error message "Run Tmie Error 91"
        Debug.Print element                      'Code wont take this line - No values get generated (element value shows Empty when i keep the curser on top of it)

        buttonClick (2).Click                    'Code wont take this line - if try to run in debugmode Error message "Run Tmie Error 91"
    Next
End Sub

Erro screenshot1 (Element showing as Empty) enter image description here

Erro screenshot2 (Eror while running the For Each element in buttonClink line and below) enter image description here

If anyone have any idea on how to resolve this issue, it will be a life saver for me. Kinldy help me, Thank you in advance for your support and time.

dhanya
  • 255
  • 1
  • 12
  • 1
    Replace `Application.wait` with reliable wait method like [here](https://stackoverflow.com/a/47084865/2165759). What is the URL? – omegastripes Nov 23 '17 at 17:05
  • Thanks @ Mat's Mug, Yes `getElementsByClassName("topmenu....stuff...")` returs some value not sure how to find that but when i keep the curser on top of it, it says `buttonclick = "[Object]"` but the `Element = Empty` – dhanya Nov 24 '17 at 08:56
  • Thanks @ omegastripes, sorry the URL wont work for anyone, bcoz this works from a secured server and this cant be accessed from any where else... And thanks for the suggestion will try to accomodate... but not usefull unless my issue get resolved :( – dhanya Nov 24 '17 at 10:28

0 Answers0