2014-10-09 123 views
0

下午好球員,XML到VBA的Excel

我想通過這個鏈接,得到一個XML文件中的表格數據,以自動化的報告:但是 http://channels9.us.dell.com/netagent/scripts/srvgate.dll?Action=10020&XMLType=A_OnlineOffline_Result

我的一切。嘗試給我錯誤。

我必須輸入用戶名和密碼,訪問此鏈接以獲得如下的XML:

<information> 
<reset>10/9/2014 8:24:07 AM</reset> 
<date>10/9/2014 10:49:45 AM</date> 
<header> 
<statheader id="0">Agent</statheader> 
<statheader id="6">Current online/offline time</statheader> 
<statheader id="1">Login time (server local)</statheader> 
<statheader id="5">Online status</statheader> 
<statheader id="4">Times offline</statheader> 
<statheader id="3">Total time offline</statheader> 
<statheader id="2">Total time online</statheader> 
</header> 
<statistics> 
<item id="41810"> 
<statistic id="0">A_G_Silva A_G_Silva</statistic> 
<statistic id="6">01:20:43</statistic> 
<statistic id="1">10/9/2014 9:29:02 AM</statistic> 
<statistic id="5">Unavailable</statistic> 
<statistic id="4">0</statistic> 
<statistic id="3">00:00:00</statistic> 
<statistic id="2">00:00:00</statistic> 
</item> 
<item id="40663"> 
<statistic id="0">Alan_Dominguez Alan_Dominguez</statistic> 
<statistic id="6">02:21:00</statistic> 
<statistic id="1">10/9/2014 8:28:45 AM</statistic> 
<statistic id="5">Unavailable</statistic> 
<statistic id="4">0</statistic> 
<statistic id="3">00:00:00</statistic> 
<statistic id="2">00:00:00</statistic> 
</item> 
</statistics> 
</information> 

你知道我怎麼能做到這一點通過VBA? 謝謝!

回答

0

添加兩個引用您的VBA項目:

  1. Microsoft Internet控制
  2. Microsoft HTML對象庫

領域背後的HTML有一個id = passwordid = username這使得它很容易找到使用getElementById

這裏是在田間填充和提交表單的工作示例:

Sub PushAddPhotoButton() 
    Dim IEexp As InternetExplorer 
    Set IEexp = New InternetExplorer 
    IEexp.Visible = True 
    IEexp.navigate "http://channels9.us.dell.com/netagent/scripts/srvgate.dll?Action=10020&XMLType=A_OnlineOffline_Result" 

    'Wait for page to load 
    Do While IEexp.readyState <> 4: DoEvents: Loop 

    'Fill in user name and password 
    IEexp.Document.getElementById("username").Value = "myUsername" 
    IEexp.Document.getElementById("password").Value = "myPassword" 

    'Submit form 
    IEexp.Document.getElementById("submit").Click 

    'Wait for page to load again 
    Do While IEexp.readyState <> 4: DoEvents: Loop 

    'Do what you need to do here to get XML 
    'If you don't do anything then the IE browser will just flicker and close 

    IEexp.Quit 
    Set IEexp = Nothing 
End Sub 

這裏是一個屏幕截圖的腳本按鈕點擊右側前停止。

enter image description here

+0

感謝您的快速回答!我收到一個錯誤:運行時錯誤'-2147417848(80010108)':自動錯誤 - 被調用的對象與客戶端斷開連接。 – lucasserafim 2014-10-09 17:04:20

+0

Set userName = IEexp.Document.getElementById(「username」) – lucasserafim 2014-10-09 17:06:01

+0

它已經用Low試過了,我仍然得到相同的錯誤。 – lucasserafim 2014-10-09 17:10:46