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)
Erro screenshot2 (Eror while running the For Each element in buttonClink
line and below)
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.