我要用VB6.0给WORD2003做一个小插件,应该怎么下手?

来源:百度知道 编辑:UC知道 时间:2024/05/15 17:04:29

1。新建>外接程序(需要VB企业版)
2。然后双设计器下的Connect,在出来的对话框中,将“应用程序”选“Microsoft Word”。
3。在工程>引用中添加对“Microsoft Word xx.0 Object Library”的引用。
4。在connect上点右键,选查看代码
5。编写代码,下面的示例代码演示如何向word添加一个QuickSearch工具栏,并在上面添加一个“划词搜索”按钮,在word中选中一些文字后点击此按钮,会打开一个IE窗口在百度中搜索当前选中的文本:
Option Explicit

Private WithEvents wdApp As Word.Application
Dim myBar As CommandBar
Private WithEvents myButton As Office.CommandBarButton

Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
Set wdApp = Application
On Error Resume Next
wdApp.CommandBars("QuickSearch").Delete
On Error GoTo 0
Set myBar = wdApp.CommandBars.Add("QuickSearch")
myBar.Visible = True
Set myButton = myBar.Controls.Add(msoControlButton)
With myButton
.Style = msoButtonCaption