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

我在EXCEL VBA中有一定的知识,但在创build与VBA的HTML交互时很新颖。

以下代码正在安全的服务器(Intranet)上工作。 在那里直到login我的代码工作完美,并在问题开始后,
1.它无法从HTML标签中选取元素。
2.设置button后 ,只需跳到End子。
3.当我尝试debugging并尝试运行跳过的代码时,可以看到错误的对象variables或块variables未设置 (请查找截图)
4.试过Debug.Print,但没有得到select的价值

VBA代码:

子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(元素显示为空) 在这里输入图像说明

Erro screenshot2(在运行ButtonClink行中的For Each element in buttonClink Eror错误) 在这里输入图像描述

如果有人对如何解决这个问题有任何的想法,那对我来说将是一个挽救生命的人。 Kinldy帮助我,预先感谢您的支持和时间。