VBA:代码审查(HTML元素识别问题)

时间:2017-11-23 16:50:50

标签: html excel vba excel-vba

我在EXCEL VBA中有适度的知识,但在创建与VBA的HTML交互时非常新。

以下代码正在使用安全服务器(Intranet)。直到登录,我的代码完美地工作,并在问题开始后,在 1.无法从HTML标记中选择元素 2.设置按钮后单击,然后跳转到End sub 3.当我尝试调试并尝试运行跳过的代码时,我可以看到错误对象变量或未设置块变量(请查看屏幕截图)
4.尝试Debug.Print但没有选择值

VBA代码:

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(元素显示为空) enter image description here

错误截图2(运行For Each element in buttonClink行及以下时发生错误) enter image description here

如果有人知道如何解决这个问题,对我来说这将是一个救命。 Kinldy帮助我,提前感谢您的支持和时间。

0 个答案:

没有答案