2017-01-20 6 views
0

Hallo Wirklich brauchen Sie hier Hilfe. Ich versuche, durch Webscrap-Ergebnisse von einer Website zu gehen und nur Problem ist, wenn ich eine ungültige Eingabe eingibt, wirft es eine Java-Alarm-Box, die ich nicht mit dem VBA-Code überwinden kann. Bitte helfenErmitteln und klicken Sie auf eine Javascript-Warnung mit vba

-Code unten

Sub TIN_VERIFY_TN() 
Dim ie As Object 
Dim form As Variant, button As Variant 
Dim pannumss As Characters 
Set ie = CreateObject("InternetExplorer.application") 

With ie 

.Visible = True 
.Navigate ("http://www.tnvat.gov.in/tamil/Tinverification.aspx") 
Do While ie.Busy: DoEvents: Loop 

countsss = WorksheetFunction.CountA(Range("A:A")) 
For X = 2 To countsss 
ie.Document.getelementsbyname("txt_tngst").Item.Value = Cells(X, 1) 

ie.Navigate "javascript:__doPostBack('LinkButton2','')" 

    Do While ie.Busy Or Not ie.ReadyState = READYSTATE_COMPLETE 
     DoEvents 
    Loop 

    Cells(X, 2) = ie.Document.getElementById("txtName").innerText 

    ie.Navigate ("http://www.tnvat.gov.in/tamil/Tinverification.aspx") 
    Do While ie.Busy: DoEvents: Loop 

    Next 
    End With 
    Set ie = Nothing 
End Sub 
gegeben

dies herausgefunden haben ist das Ereignis, das die msgbox

<Script language='javascript'>alert('Invalid TIN No');</script><script language='javascript'>document.getElementById('txt_tngst').focus();</script></form> 
     </body> 
    </HTML> 

wirklich jede Hilfe dankbar ist die Schaffung i wie bekommen, wie kann ich wissen, Wenn der Alarm ausgelöst wurde und wie ich den Alarm schließen soll, sobald er angezeigt wird

+0

http://stackoverflow.com/questions/9486847/close-javascript-alert-using-vba-automation –

+0

http://stackoverflow.com/questions/ 18075762/vba-close-java-alerts-popups-mit-name-message-from-webpage? Rq = 1 –

+0

Können Sie bitte eine gültige 'TIN No' zum Testen bereitstellen? – omegastripes

Antwort

0

Versuchen Sie es mit vorh ent Ausführung von Skripten durch .execCommand "stop" vor Readystate wird vollständig:

Sub TIN_VERIFY_TN() 

    Const READYSTATE_UNINITIALIZED = 0 
    Const READYSTATE_LOADING = 1 
    Const READYSTATE_LOADED = 2 
    Const READYSTATE_INTERACTIVE = 3 
    Const READYSTATE_COMPLETE = 4 

    Dim ie As Object 
    Dim form As Variant, button As Variant 
    Dim pannumss As Characters 
    Dim cnt As Long 
    Dim x As Long 
    Dim a 

    Set ie = CreateObject("InternetExplorer.application") 
    With ie 
     .Visible = True 
     cnt = WorksheetFunction.CountA(Range("A:A")) 
     For x = 2 To cnt 
      .Navigate "http://www.tnvat.gov.in/tamil/Tinverification.aspx" 
      Do While .busy Or Not .readyState = READYSTATE_COMPLETE: DoEvents: Loop 
      .document.getElementsByName("txt_tngst").Item.Value = Cells(x, 1) 
      .document.parentWindow.execScript "__doPostBack('LinkButton2','')", "javascript" 
      Do While .readyState < READYSTATE_INTERACTIVE: DoEvents: Loop 
      .document.execCommand "stop" 
      Do While .busy Or Not .readyState = READYSTATE_COMPLETE: DoEvents: Loop 
      a = Array(.document.getElementById("txtName")) 
      If TypeName(a(0)) <> "Null" Then Cells(x, 2) = a(0).innerText 
     Next 
    End With 

End Sub 
+0

Hallo Omega. Danke für den Code. Der Code scheint die Submit-Funktion jetzt nicht auszuführen. Im Grunde lädt der folgende Code das Ergebnis .document.parentWindow.execScript nicht " –

Verwandte Themen