无法从网页中选择价值并将其转化为Excel

时间:2014-04-24 05:53:38

标签: html excel-vba vba excel

我是VBA的新手, 我想从网页上的一些数据到excel表.. 我编写了访问网页,输入值和点击提交按钮的代码。 点击提交按钮,下一个网页出现..我想从该网页的电子邮件ID到我的excel表..请帮助

我写的代码如下:

Sub emailforcform()
Dim ie As InternetExplorer
Dim html As HTMLDocument

Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "https://registration.apct.gov.in/ctdportal/Search/EMailSearch.aspx"
Do While ie.readyState <> READYSTATE_COMPLETE
Application.StatusBar = "Trying to connect"
DoEvents
Loop

Set html = ie.document
ie.document.all("ctl00$ContentPlaceHolder1$TxtTin").Value = "28740213505"
ie.document.all("ctl00$ContentPlaceHolder1$ButGet").Click
Range("c4").Value = ie.document.all("ContentPlaceHolder1_UpdatePnl").Value

End Sub

1 个答案:

答案 0 :(得分:0)

这对我有用......

Sub test()
    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "https://registration.apct.gov.in/ctdportal/Search/EMailSearch.aspx"

    Application.StatusBar = "Trying to connect"

    Do Until Not ie.Busy And ie.readyState = 4
          DoEvents
    Loop

    ie.Document.all("ctl00$ContentPlaceHolder1$TxtTin").Value = "28740213505"
    ie.Document.all("ctl00$ContentPlaceHolder1$ButGet").Click

    Application.StatusBar = "Preparing to retrieve the email ID"

    Do Until Not ie.Busy And ie.readyState = 4
          DoEvents
    Loop

    Range("c4").Value = ie.Document.getElementsByTagName("tbody")(7).getElementsByTagName("tr")(1).getElementsByTagName("td")(1).innertext
end sub