|
楼主 |
发表于 2016-3-15 17:08
|
显示全部楼层
本帖最后由 henrylam 于 2016-3-17 09:54 编辑
直接将XML代码写在“Connect”项会有行继续标志限制,因此可以将XML代码写到资源文件中,操作方法如下:
1.先用记事本编写好用于自定义功能区的XML代码;
2.到VB6.0菜单栏“工具”中,打开“资源编辑器”,新建或选中文件,点击“acb”打开“编辑字符串表”,然后将XML代码复制、粘贴到“101”右边框中,保存即可;
3.在“Connect”项编写调用代码。
- Option Explicit
- Implements IRibbonExtensibility '添加对 IRibbonExtensibility 接口的引用
- Public xlApp As Excel.Application
- Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
- Set xlApp = Application '加载时
- End Sub
- Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
- Set xlApp = Nothing '卸载时
- End Sub
- '调用资源文件中的XML代码用于自定义功能区
- Public Function IRibbonExtensibility_GetCustomUI(ByVal RibbonID As String) As String
- IRibbonExtensibility_GetCustomUI = LoadResString(101)
- End Function
- 'Button1用的是系统内置图标,无需调用。Button2和Button3用的是自定义图标
- Function GetImage(control As IRibbonControl) As IPictureDisp
- Select Case control.Id
- Case "Button2"
- Set GetImage = LoadResPicture(101, vbResBitmap) '调用资源文件中的位图作为功能区的图标
- Case "Button3"
- Set GetImage = LoadResPicture(102, vbResBitmap)
- End Select
- End Function
- '下面是测试控件回调的3个过程,对应3个按钮
- Public Sub test1(ByVal control As IRibbonControl)
- MsgBox "测试通过,按钮用的是内置图标", vbInformation
- End Sub
- Public Sub test2(ByVal control As IRibbonControl)
- MsgBox "测试通过,按钮用的是自定义图标", vbInformation
- End Sub
- Public Sub test3(ByVal control As IRibbonControl)
- If Not xlApp.ActiveWorkbook Is Nothing Then
- xlApp.ActiveWorkbook.FollowHyperlink Address:="http://club.excelhome.net/thread-791154-1-1.html", NewWindow:=True
- Else
- MsgBox "没有活动工作簿", vbExclamation
- End If
- End Sub
复制代码 VB工程文件
补充更新.rar
(54.41 KB, 下载次数: 491)
|
评分
-
2
查看全部评分
-
|