2014-06-30 4 views
0

VBA IE : http://rgl.faa.gov/Regulatory_and_Guidance_Library/rgAD.nsf/MainFrame?OpenFrameset나는 웹 사이트 쿼리해야하는 프로세스 자동화하기 위해 노력하고 자동화

내가 채울하려는 입력 텍스트 필드 <input name="query size="20"/>" 있습니다하지만 난 그렇게 할 고군분투하고있다. 현재 태그를 참조 할 수 있는지 여부를 확인하기 위해 코드를 테스트하고 있습니다.

Sub fill() 
Dim IE As Object 
Set IE = CreateObject("InternetExplorer.Application") 

IE.navigate "http://rgl.faa.gov/Regulatory_and_Guidance_Library/rgAD.nsf/MainFrame?OpenFrameset" 
IE.Visible = True 
While IE.busy 
DoEvents 
Wend 

For Each it In IE.Document.getElementsByTagName("input") 
      If it.Name = "newquery" Then 
       MsgBox ("yup") 
      End If 
     Next 
End Sub 

나는이 할 경우에도 가능하면

모든 아이디어 ... 내 문제는 입력 필드 2 프레임 세트와 프레임에 있다고 생각?

답변

4

당신이 알고하지 않는 한 정확히 어떤 프레임 입력이 재귀 검색을위한 고전적인 상황에 있습니다 : http://codecentrix.com/download.html

하지 마십시오 :

Sub fill() 
    Dim IE As Object, elem As Object 
    Set IE = CreateObject("InternetExplorer.Application") 

    IE.navigate "http://rgl.faa.gov/Regulatory_and_Guidance_Library/rgAD.nsf/MainFrame?OpenFrameset" 
    IE.Visible = True 

    While IE.Busy: DoEvents: Wend 
    While IE.document.readyState <> "complete": DoEvents: Wend 

    Set elem = FindInputByName(IE.document, "newquery") 
    If Not elem Is Nothing Then 
    elem.Value = "It works!" 
    End If 
End Sub 

Function FindInputByName(document As Object, name As String) As Object 
    Dim i As Integer, subdocument As Object, elem As Variant 
    Set FindInputByName = Nothing 

    For i = 0 To document.frames.Length - 1 
    Set subdocument = document.frames.Item(i).document 
    Set FindInputByName = FindInputByName(subdocument, name) 
    If Not FindInputByName Is Nothing Then Exit Function 
    Next i 

    For Each elem In document.getElementsByTagName("INPUT") 
    If elem.name = name Then 
     Set FindInputByName = elem 
     Exit Function 
    End If 
    Next elem 
End Function 
+0

,하지만 난 그것을 개체가이 속성을 지원하지 않거나 "고 saids 몇 가지 오류에 달렸다 방법." 디버깅 할 때 함수의 영역을 하이라이트합니다. 각 프레임에서 document.frames .. – ltsai

+0

'frames' 컬렉션은'For Each'를 허용하지 않습니다. 나는 정규적인 'For' 루프로 대체했습니다. 이제는 작동하는 것 같습니다. IE.document.readyState <>가 "IE.Busy"를 폴링하는 것보다 낫다고 생각하지만, 완전히 확신 할 수는 없다. YMMV. – Tomalak

+0

내가 뭘 잘못하고 있는지 모르겠지만 코드를 복사하여 붙여 넣은 다음 "ByRef 인수 유형 불일치"라는 새로운 오류가 발생했습니다. ByVal을 변경해 보았는데 예상대로 작동하지 않았습니다. – ltsai

0

당신은 설치 및 라이브러리를 opentwebst 사용하려고합니다 프로젝트 참조에 opentwebst를 추가하는 것을 잊어 버리십시오.

는 그 다음이 게시물을 작성 아래의 코드를 생성하기 위해 나에게 적은 시간에 나섭니다 : 내가 코드를 실행하려고

Sub OpenTwebstMacro 
    Dim core As ICore 
    Set core = New OpenTwebstLib.core 

    Dim browser As IBrowser 
    Set browser = core.StartBrowser("http://rgl.faa.gov/Regulatory_and_Guidance_Library/rgAD.nsf/MainFrame?OpenFrameset") 

    Call browser.FindElement("input text", "name=newquery").InputText("YOUR QUERY") 
    Call browser.FindElement("input button", "uiname=Go").Click 
End Sub 
관련 문제