WORD VBA 右键菜单添加Google或Baidu搜索功能d的问题

来源:百度知道 编辑:UC知道 时间:2024/06/16 23:42:17
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 = &qu

奇怪,我这里运行有效果啊,的确在Word文档窗口的右键菜单里面出现了“Google搜索”和“百度搜索”两个菜单项了。

楼主能把你的操作步骤简单讲一下吗?

______
补充:
在列表文字上点击右键的菜单是CommandBars("Lists"),这区别于普通文本的右键菜单CommandBars("Text")。
你可以做个试验用个循环把所有CommandBar的Name用Debug.Print打出来看看,如果有需要的都在你上面的代码里面处理一下。