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

问题描述 投票:0回答:1

我正在尝试打开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

我希望我可以点击这个按钮

excel vba internet-explorer
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.