为什么代码没有单击按钮?

时间:2019-04-22 19:08:48

标签: excel vba internet-explorer

我正在尝试打开IE窗口,然后单击按钮以自动执行重复的工作。代码打开了窗口,但是没有单击按钮,没有任何帮助吗?

按钮具有以下代码:

<a tabindex="0" title="Criar Solicitação de Manutenção" 
  class="urLnkReportGl20 urTxtEmph" id="WD54" 
  style="WHITE-SPACE: nowrap" 
  ondragstart="var e=window.event;e.cancelBubble=true;e.returnValue=false;return false;"
   href="javascript:void(0);" shape="" ti="0" 
  lsevents="{Activate:[{ResponseData:'delta',ClientAction:'submit'},{}]}" 
  lsdata="{0:'Criar\x20Solicita\xe7\xe3o\x20de\x20Manuten\xe7\xe3o',1:'CRIAR\x20SOLICITA\xc7\xc3O\x20DE\x20MANUTEN\xc7\xc3O',4:true}" 
  ct="LN"
<img align="absMiddle" ondrag="return false" 
   alt="Criar Solicitação de Manutenção" src="http://dest-pb0l03.sap.global.*****:8000/sap/public/bc/WebIcons/ur/default/l/Pictogram/Caliper.gif" border="0"</img> CRIAR SOLICITAÇÃO DE MANUTENÇÃO
</a>

我正在使用的代码是这样:

Sub VbaInternet()

Set Internet = New InternetExplorer
Internet.navigate "http://dest-pb0l03.sap.global.*****:8000/sap/bc/webdynpro/sap/zpm_portal?sap-language=PT"
Internet.Visible = True

While Internet.Busy
    Do While Internet.readyState = 4: DoEvents: Loop   'Do While
    Do Until Internet.readyState = 4: DoEvents: Loop   'Do Until
Wend

Dim oElement As Object 'Objeto referente a um Elemento
Dim oElementCol As Object 'Coleção de um tipo de Elemento


Set oElementCol = Internet.document.getElementsByTagName("a")


  'Ao encontrar, é simulado o Click e força a saída do laço.
  If oElement.className Like "urLnkReportGl20 urTxtEmph" Then

  oElement.Click

End If
  Next oElement
End Sub

我希望我可以单击此按钮

1 个答案:

答案 0 :(得分:0)

您可以通过标准的页面加载等待尝试一下,让我知道您返回的错误代码吗?

Option Explicit
'VBE > Tools > References: Microsoft Internet Controls
Public Sub ClickButton()
    Dim ie As InternetExplorer
    Set ie = New InternetExplorer

    With ie
        .Visible = True
        .Navigate2 "yourURL"

        While .Busy Or .readyState < 4: DoEvents: Wend

        .document.getElementById("WD54").Click

        Stop
    End With
End Sub