2。 Then connect under the double designer, and select "Application" as "Microsoft Word" in the dialog box that comes out.
3。 Add a reference to the Microsoft Word xx.0 object library in project > references.
4。 Right-click the connection and select View Code.
5。 Write code. The following sample code demonstrates how to add a quick search toolbar in word and add a "stroke word search" button on it. Click this button after selecting some words in Word, and an IE window will open to search the currently selected words in Baidu:
Option explicit
Private WithEvents wdApp As Word。 app; application
Show my toolbar as a command bar
Private sets my button to Office. CommandBarButton
Private subaddininstance _ onconnection (byval application as object, ByVal ConnectMode as addindesignerobjects. ext _ connectmode, ByVal AddInInst as object and custom () as variable).
Set wdApp = application
Continue to the next step when an error occurs.
wdApp。 CommandBars ("quick search"). delete
Go to 0 when an error occurs.
Set myBar = wdApp. CommandBars.Add("QuickSearch ")
Mine. Visible = true
Set myButton = myBar. Controls.Add(msoControlButton)
Use my button
. Style = msoButtonCaption
. Caption = "Word stroke search"
End with ...
End joint
Private subaddininstance _ on disconnection (byval remove mode as addindesignerobjects. ext _ disconnect mode, custom () as Variant).
Continue to the next step when an error occurs.
wdApp。 CommandBars ("quick search"). delete
Go to 0 when an error occurs.
Set wdApp = Nothing.
End joint
private Sub my button _ Click(ByVal Ctrl As Office。 CommandBarButton, CancelDefault is a boolean value)
Dim ie
If wdApp. choose Text & lt& gt ""So?
set ie = CreateObject(" internet explorer . application ")
Namely. Visible = true
ie.navigate? wd = " & ampwdApp。 select
If ... it will be over.
End joint
Private sub wdapp _ windowselectionchange (byvalsel is Word. Select)
If Sel. Text = ""So
My button. Enabled = False
other
My button. Enabled = true
If ... it will be over.
End joint
6. After you can see the "Quick Search" toolbar, you can compile it into a Dll. If you want to copy it to another computer, you need to register it with the command "regsvr 32[ full path of compiled dll file]" or use the menu command "Tools > > COM Add-ins" to load or unload it.
Using VB6.0 as the plug-in of word can not only realize the above functions, but also modify the right-click menu of word program, call various properties and methods of many objects in word, and respond to events provided by word. At the same time, it has the advantages of using custom controls, control arrays, resource files and codes in VB6, which makes up for the shortcomings of word VBA.