2014-05-19 4 views
0

Excel 용 웹 쿼리를 만들려고하는데 약간의 걸림돌이 생겼습니다. 웹 페이지에 로그인하고 링크를 클릭하여 올바른 portalID로 이동하는 방법을 알아 냈습니다. 그러나 특정 보고서를받는 데 문제가 있습니다.Excel VBA 자바 스크립트에 의해 제어되는 테이블에있는 셀을 클릭하십시오

특정 보고서를 보려면 표에서 해당 링크를 클릭해야하지만 자바 스크립트가 사용 된 것으로 보입니다. 이 표의 HTML은 다음과 같습니다. 이 표에는 약 10 개의 셀이 있지만 코드 라이트를 유지하기 위해 처음 2 개의 셀만 포함했습니다. 보시다시피 각 셀에는 고유 한 ID가 있으므로 VBA를 사용하여 올바른 셀 요소로 쉽게 필터링 할 수 있습니다. 그러나 실제로 셀을 클릭하는 방법을 알아낼 수 없습니다.

<table submenu='1' border='0' cellpadding='6' cellspacing='0' 
id='ctl02n4c73594f1bf740b982340da2a792ff62_MainM' 
class="ctl02n4c73594f1bf740b982340da2a792ff62Island" 
style=' background:#141311; border-width:0px; width:100%; 
cursor:Default;' onselectstart="javascript:igmenu_selectStart();" 
onmouseover="javascript:igmenu_mouseover(this, event);" 
onmouseout="javascript:igmenu_mouseout(this, event);" 
onmousedown="javascript:igmenu_mousedown(this, event);" 
onmouseup="javascript:igmenu_mouseup(this, event);"igLevel='0'> 
    <tr> 
    <td align='center' id='ctl02n4c73594f1bf740b982340da2a792ff62_1' 
    igTag='4eddf201-f6ed-4e11-b2ff-6a742128909c' 
    class="n_4c73594f_1bf7_40b9_8234_0da2a792ff62_Class"style=" 
    white-space: nowrap; ;" igHov='n_4c73594f_1bf7_40b9_8234_0da2a792ff62_Hover' 
    igTop='1'>Welcome</td> 
    <td align='center' id='ctl02n4c73594f1bf740b982340da2a792ff62_2' 
    igTag='e0d4474e-87f8-42cc-ab47-38751029052d' 
    class="n_4c73594f_1bf7_40b9_8234_0da2a792ff62_Class"style=" 
    white-space: nowrap; ;" igHov='n_4c73594f_1bf7_40b9_8234_0da2a792ff62_Hover' 
    igTop='1'>Dashboard</td> 
    </tr> 
</table> 

클릭해야하는 셀로 직접 연결되는 내 vba입니다. 내가 테이블의 "onmouseup"이벤트를 호출해야하는 것처럼 보입니다. 내가 필요한 셀을 테이블의 onmouseup 이벤트와 어떻게 "링크"합니까?

Sub clickTable(toFind As String, ie As Object) 
'"toFind" is the ID of the cell to find, ie is the IE application 
Dim ieDoc As Object 'ieDocDocument 
Dim tdCollection As Object 'table that has the javascript events and contains 
          the cells I want to click 
Dim cell As Object 'specific "clickable" cell in the table to "click" 

    Set ieDoc = ie.document 
    Set tdCollection = ieDoc.getelementbyID("ctl02n4c73594f1bf740b982340da2a792ff62_MainM").getElementsByTagName("td") 
    For Each cell In tdCollection 
     If cell.ID = toFind Then 
      cell.Click 
      Exit Sub 
     End If 
    Next 

End Sub 

답변

2

글쎄, 다른 vba/javascript 질문을 검색하는 동안 실제로 내 자신을 알아 냈어!

모든 자바 스크립트 코드를 통해 HTML 이벤트가 자바 스크립트에 연결되어 있는지 확인하고 "onmouseup"에는 "onmouseover"가 필요한 onmousedown이 필요합니다. 여기에서는 최종 상호 작용을 실행하려고 시도하고 자바 스크립트 코드를 분해하지도 않았습니다.

다른 사람이 자바 스크립트 제어 테이블 메뉴에서 셀을 클릭하는 중 문제가 발생하면 자바 스크립트 작성 방법에 따라 마우스가 페이지와 상호 작용하는 모든 방법을 실행해야 할 수도 있습니다.

다음은 마지막 코드입니다.

Sub clickTable(toFind As String, ie As Object) 
'toFind is the ID of the element to find, ie is the IE application 
Dim ieDoc As Object 'ieDocDocument 
Dim tdCollection As Object 'table that has the javascript attributes and contains the element I want to click 
Dim cell As Object 'specific "clickable" cell in the table to test 

     Set ieDoc = ie.document 
     Set tdCollection = ieDoc.getelementbyID("ctl02n4c73594f1bf740b982340da2a792ff62_MainM").getElementsByTagName("td") 
     For Each cell In tdCollection 
      If cell.ID = toFind Then 
       cell.FireEvent ("onmouseover") 
       cell.FireEvent ("onmousedown") 
       cell.FireEvent ("onmouseup") 
       Exit Sub 
      End If 
     Next 

    End Sub