Excel VBA 打开百度网页输入关键字并搜索

Sub 百度搜索()
'Excel VBA 打开百度网页输入关键字并搜索
Dim KW, Su
With CreateObject("InternetExplorer.Application")
.Navigate "http://www.baidu.com/"
.Visible = True
Do Until .readyState = 4
DoEvents
Loop
'Set KW = .document.getElementsByName("wd")
'KW.Item(0).Value = "QQ"
.document.getElementsByName("wd").Item(0).Value = "QQ" '等同上面2句
'Set Su = .document.getElementByid("f")
'Su.Submit
.document.getElementByid("f").Submit '等同上面2句
End With
Set Su = Nothing
Set KW = Nothing
End Sub


  • 1
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Option Explicit Private Sub CommandButton1_Click() Dim ar, br(), i&, j&, k&, m&, myFile$, myPath$, myStr$, Rng As Range, Wb, Ws, tms# Application.ScreenUpdating = False On Error Resume Next If Range("n3") = "" Then MsgBox "N列中没有要查询的内容": Exit Sub m = Range("n2").End(4).Row - 1 ar = Range("n2").Resize(m) ReDim br(65530, 5) With Application.FileDialog(msoFileDialogFolderPicker) If .Show Then myPath = .SelectedItems(1) Else myPath = ThisWorkbook.Path End With If Right(myPath, 1) <> "\" Then myPath = myPath & "\" tms = Timer myFile = Dir(myPath & "*.xls*") Do While myFile <> "" If myFile <> ThisWorkbook.Name Then br(k, 1) = Left(myFile, InStrRev(myFile, ".") - 1) Set Wb = GetObject(ThisWorkbook.Path & "\" & myFile) With Wb '利用GetObject在后台打开工作簿 For Each Ws In .Worksheets '循环当前工作簿中每个工作表 br(k, 2) = Ws.Name With Ws For i = 2 To m myStr = ar(i, 1) If WorksheetFunction.CountIf(.UsedRange, "*" & myStr & "*") <> 0 Then Set Rng = .UsedRange.Find(myStr) Do br(k, 3) = Rng.Address(0, 0) br(k, 4) = Rng.Text br(k, 5) = myStr br(k, 0) = k + 1 k = k + 1 br(k, 1) = br(k - 1, 1) br(k, 2) = br(k - 1, 2) Set Rng = .UsedRange.Find(myStr, Rng) Loop While .UsedRange.Find(myStr).Address <> Rng.Address End If Next End With Next Ws .Close False '不保存关闭工作簿 End With End If myFile = Dir Loop Set Wb = Nothing Range("a1").CurrentRegion.Offset(2) = "" myStr = "很遗憾、不存在你要搜索的内容。" If k Then Range("a3").Resize(k, 6) = br Range("a3").Resize(k, 6).Borders.LineStyle = 1 以下还有内容……见附件!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值