|
こんな感じでしょうか。
タイミングの問題で、うまくいかないことがありました。
時間待ちのところは適宜調節してみてください。
Private Declare Sub Sleep Lib "KERNEL32.dll" (ByVal dwMilliseconds As Long)
'参照設定 Microsoft Internet Controls(Microsoft Browser Helpers)
'Microsoft HTML Object Library の 2つを忘れずに
Sub test()
Dim objIE As Object
Dim sht As Worksheet
Dim result
Dim s As String
Dim k As Long
Dim placeholder As Object
Dim ss As String
Set sht = Sheets("Sheet1")
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Visible = True 'デバッグ中は可視にしたほうが良い
.Navigate "★//www.englishnepalidictionary.com" '5文字省略
While objIE.readyState <> READYSTATE_COMPLETE Or objIE.Busy = True
DoEvents
Wend
DoEvents
For k = 2 To sht.Range("A1").End(xlDown).Row
s = sht.Cells(k, 1).Value
Set placeholder = .document.getElementById("q")
placeholder.Value = s
.document.getElementById("btnSearch").Click
While objIE.readyState <> READYSTATE_COMPLETE Or objIE.Busy = True
DoEvents
Wend
Sleep 1000
ss = .document.getElementsByTagName("h3").Item(0).innerText
sht.Cells(k, 2).Value = Replace(ss, s & " - ", "")
Next
End With
objIE.Quit
Set objIE = Nothing
End Sub
|
|