2014-10-09 3 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 Controls
  2. Библиотека объектов
  3. Microsoft HTML

HTML, за полями имеет id = password и id = 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

+0

Set userName = IEexp.Document.getElementById ("username") – lucasserafim

+0

Это уже было сделано с использованием Low, и я все равно получаю ту же ошибку. – lucasserafim

Смежные вопросы