단순히 인터넷 익스플로워를 띄우는 방법
아래는 열려있는 창이 있으면 열려있는 익스플로워의 첫번째 창을 이용해서
네이버 검색을 하는 예제입니다.
naver.com에서 "네이버"를 검색해서 관련 연관검색어를 메세지 박스로 띄워줍니다.
Dim IE As Object
Sub 버튼()
If IE Is Nothing Then Set IE = FindIE
On Error Resume Next
With IE
.Visible = True
.Navigate2 "naver.com"
If Err Then Set IE = Nothing: 버튼: Exit Sub
Do While .Busy = True Or .ReadyState <> 4
DoEvents
Loop
.Document.all("query").Value = "네이버"
.Document.all("search_btn").Click
Do While .Busy = True Or .ReadyState <> 4
DoEvents
Loop
MsgBox .Document.all("nx_related_keywords").innerTEXT
End With
End Sub
Function FindIE() As Object
Dim obj As Object, Count&, URL$, Title$, x&
Set obj = CreateObject("Shell.Application")
On Error Resume Next
Count = obj.Windows.Count
For x = 0 To (Count - 1)
URL = obj.Windows(x).Document.Location
Title = obj.Windows(x).Document.Title
If TypeName(obj.Windows(x).Document) = "HTMLDocument" Then
Set FindIE = obj.Windows(x)
Exit For
End If
Next
If FindIE Is Nothing Then Set FindIE = CreateObject("InternetExplorer.Application")
End Function