使用VB快速制作WPS的COM加载项
-09-14
1.新建工程,选择ActiveX Dll。
2.工程、引用、选择Kingsoft Add-In Designer、Kingsoft Office 1.0 Object Library、Kingsoft WPS 2.0 object Library。
3.将工程名原来的“工程1”改为“kgsPro”,类名称的“Class1”改为“AddCommand”
(这里的修改的名称根据实际情况而定义,但在后面的注册时会用到这两个名字)
4.写入如下的代码:Option Explicit
Implements IDTExtensibility2
Private WithEvents wpsApp As WPS.Application
Private WithEvents btnNew As CommandBarButton
Private myId As Integer
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
Set wpsApp = Application
End Sub
Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
Set wpsApp = Nothing
End Sub
Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
Dim myBar As CommandBar
Set myBar = mandBars.Add("测试工具栏")
Set btnNew = myBar.Controls.Add
End Sub
Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
"通常这些不需要写
End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
btnNew.Delete "删除加载项
End Sub
Private Sub btnNew_Click(ByVal Ctrl As mandBarButton, CancelDefault As Boolean)
"wpsApp.ActiveDocument.BeginJob
MsgBox "这是一个Demo", vbOKOnly, "kongguisheng"
"wpsApp.ActiveDocument.EndJob "这仅仅是一个Demo", True
End Sub
复制代码
5.单击文件、生成***.dll,保存到C盘下,文件名为kgsPro.dll。
6.Dll生成完成,下面就是注册的步骤了。
7.新建一个文本文档,保存为AddDemo.reg,写入如下的内容
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Kingsoft\Office\WPS\Addins\kgsPro.AddCommand]
"FriendlyName"="WPS加载项Demo"
"Description"="Konguisheng的Demo系列之加载项"
"LoadBehavior"=dword:00000003
"CommandLineSafe"=dword:00000001
8.双击AddDemo.reg,将此导入到注册表中。
9.单击Windows的“运行”,输入regsvr32 C:\kgsPro.dll完成
10.如果要删除这个加载项
A.新建一个文本文档,保存为DeleteDemo.reg,写入如下的内容
Windows Registry Editor Version 5.00
[-HKEY_CURRENT_USER\Software\Kingsoft\Office\WPS\Addins\kgsPro.AddCommand]
B.单击Windows的“运行”,regsvr32 /u C:\kgsPro.dll (此步不是必须)
免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。
/style/images/nopic.gif