声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 3021|回复: 0

[科研工具] Office右键菜单中添加Google或Baidu搜索

[复制链接]
发表于 2009-6-18 11:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
在word中选中文字,点击右键,菜单里面有个google搜索功能,点击后可直接启动当前默认浏览器对选中的文字进行搜索。

具体在工具->宏->VB编辑器中打开,把下面的文字插入到Normal模板的模块中,重新运行就会出现搜索菜单了。
http://hi.baidu.com/juncox/blog/item/e7438981b0080fde9123d91c.html


'功能简介: 在右键文本菜单的第一项, 添加一个Google和Baidu搜索命令
'Creator: Juncox,
'Email:   Juncox@163.com
'----------------------
Private Sub Document_Close()
    On Error Resume Next
    Application.CommandBars("Text").Controls("Google搜索").Delete   '恢复原有菜单
    Application.CommandBars("Text").Controls("Baidu搜索").Delete   '恢复原有菜单
    Application.CommandBars("Text").Reset '重新设置右键菜单,彻底恢复默认设置
End Sub

'----------------------
Private Sub Document_Open()
    On Error Resume Next
    Dim BtnGoogle As CommandBarButton
    Dim BtnBaidu As CommandBarButton
    Application.CommandBars("Text").Controls("Google搜索").Delete   '预防性删除
    Application.CommandBars("Text").Controls("Baidu搜索").Delete   '预防性删除
    Application.CommandBars("Text").Reset '重新设置右键菜单,彻底恢复默认设置
    Set BtnGoogle = Application.CommandBars("Text").Controls.Add(Type:=msoControlButton, Before:=1) '第一项
    Set BtnBaidu = Application.CommandBars("Text").Controls.Add(Type:=msoControlButton, Before:=2) '第二项
    With BtnGoogle
      .Caption = "&Google搜索" '命令名称
      .FaceId = 86             '命令的FaceId,字母G
      .Visible = True           '可见
      .OnAction = "GoogleSearch"       '指定响应过程名
    End With
    With BtnBaidu
      .Caption = "&Baidu搜索" '命令名称
      .FaceId = 81             '命令的FaceId
      .Visible = True           '可见
      .OnAction = "BaiduSearch"       '指定响应过程名
    End With
End Sub

'----------------------
Sub GoogleSearch()
    Dim sSearch$, sSel$
    sSel = Trim(Selection.Text)
    'If Len(sSel) <= 1 Then
    '  MsgBox "选择的文本太少,不能进行搜索!" & vbCrLf & "最少两个字符!!! Juncox@163.com", vbInformation + vbOKOnly, "Google搜索"
    'Else
      sSearch = "explorer ""http://www.google.cn/search?client=Juncox&hl=zh-CN&q=" & sSel & """"    '两种形式结果是一致的
      sSearch = "explorer " & Chr(34) & "http://www.google.cn/search?client=Juncox&hl=zh-CN&q=" & sSel & Chr(34)
      Shell sSearch
    'End If
End Sub

Sub BaiduSearch()
    Dim sSearch$, sSel$
    sSel = Trim(Selection.Text)
    'If Len(sSel) <= 1 Then
    '  MsgBox "选择的文本太少,不能进行搜索!" & vbCrLf & "最少两个字符!!! Juncox@163.com", vbInformation + vbOKOnly, "Google搜索"
    'Else
      sSearch = "explorer ""http://www.baidu.com/baidu?tn=Juncox&word=" & sSel & """"
      sSearch = "explorer " & Chr(34) & "http://www.baidu.com/baidu?tn=Juncox&word=" & sSel & Chr(34)
      Shell sSearch
    'End If
End Sub

[ 本帖最后由 Juncox 于 2009-6-18 15:22 编辑 ]
回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-20 14:44 , Processed in 0.058243 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表