美文网首页VBA
【Excel VBA】从excel单元格直接导出关键词搜索百度

【Excel VBA】从excel单元格直接导出关键词搜索百度

作者: 极客Geek | 来源:发表于2021-07-25 09:42 被阅读0次

【Excel VBA】从excel单元格直接导出关键词搜索百度

参考1:

代码:

Sub Google()
Dim myFind As String, Response As Integer
myFind = Replace(Trim(Selection.Text), " ", "+")
Response = MsgBox("是否需加引号搜索?", vbYesNoCancel)
Select Case Response
Case vbYes
myFind = "“" & myFind & "”"
Case vbCancel
Exit Sub
End Select
Shell ("C:\Program Files\Internet Explorer\iexplore.exe " & myFind)
End Sub

这个有点复杂,并且测试运行报错:


参考2

简洁修改一下
代码:

Sub Google()
Dim myFind As String, Response As Integer
myFind = Replace(Trim(Selection.Text), " ", "+")
Shell ("C:\Program Files\Internet Explorer\iexplore.exe " & myFind)
End Sub

简洁后测试也报错,也不行:


参考3

添加搜索引擎, 百度的或者谷歌,不用哪个注释掉哪个(行前加 ` 可以注释):

Sub mySearching()
    '以选中内容为搜索关键词
    Dim mySearchEngine As String
    'mySearchEngine = "http://www.google.cn/search?hl=zh-CN&q="  'Google搜索
    mySearchEngine = "http://www.baidu.com/s?wd="  '百度搜索
    Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE " & mySearchEngine & Selection.Text, 1
End Sub

添加搜索引擎后,测试成功


个人使用修改版

根据
参考1和2的 Trim(Selection.Text)命令,
参考3的 mySearchEngine = "http://www.baidu.com/s?wd="
加上自己使用的浏览器,修改路径C:\Users\Administrator\AppData\Local\CentBrowser\Application\chrome.exe
改出适合自己使用的VBA

Sub mySearching()
    Dim mySearchEngine As String,  myFind As String
    myFind = Trim(Selection.Text)
    mySearchEngine = "http://www.baidu.com/s?wd=" 
    'mySearchEngine = "http://www.bing.com/search?q=" 
    Shell "C:\Users\Administrator\AppData\Local\CentBrowser\Application\chrome.exe " & mySearchEngine & myFind, 1
End Sub

测试成功

END

相关文章

网友评论

    本文标题:【Excel VBA】从excel单元格直接导出关键词搜索百度

    本文链接:https://www.haomeiwen.com/subject/wulimltx.html