Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3500|回复: 8

谁能告诉我怎么封装这个文档成Dll

[复制链接]
发表于 2012-1-24 22:58 | 显示全部楼层 |阅读模式
50学分
注意:当活动工作表为空白工作表时,【拆分数据】按钮不可用。当活动工作表不为空时,【拆分数据】按钮可用。
自由控制按钮是否可用.rar (18.53 KB, 下载次数: 85)

最佳答案

查看完整内容

先要看效果是不是满足要求啊,源码上传 Option Explicit Private WithEvents xlApp As Excel.Application 'Note: No error handling is implemented in the example. 'Only the usual references are used for the project, i e Office 12 and Excel 12. 'In order to customize the Ribbon UI the IRibbonExtensibility must be implemented. Implements IRibbonExtensibility Dim MailRib As IRibbonUI Privat ...
发表于 2012-1-24 22:58 | 显示全部楼层
先要看效果是不是满足要求啊,源码上传

Option Explicit

Private WithEvents xlApp As Excel.Application

'Note: No error handling is implemented in the example.
'Only the usual references are used for the project, i e Office 12 and Excel 12.
'In order to customize the Ribbon UI the IRibbonExtensibility must be implemented.
Implements IRibbonExtensibility

Dim MailRib As IRibbonUI

Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
                                       ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
'The variable xlApp is declared in a standard module.
    Set xlApp = Application
End Sub

Private Sub AddinInstance_OnDisconnection _
        (ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
'Release the object from memory.
    Set xlApp = Nothing
End Sub

Public Function IRibbonExtensibility_GetCustomUI(ByVal RibbonID As String) As String
'Parse the XML to the Ribbon.
    IRibbonExtensibility_GetCustomUI = LoadResString(101)
End Function

'Callback for customUI.onLoad
Sub RibbonOnLoad(ribbon As IRibbonUI)
    Set MailRib = ribbon
End Sub

'Callback for data1 getEnabled
' 由工具Custom UI Editor for Microsoft Office 2010产生的回调申明为:
'   Sub EnabledIRibbonA(control As IRibbonControl, ByRef returnedVal)
' 这个适用于VBA,用于COM中时要进行修改
Function EnabledIRibbonA(control As IRibbonControl) As Boolean
    EnabledIRibbonA = Not IsEmpty(xlApp.ActiveSheet.UsedRange)
End Function

'Callback for data1 onAction
Sub IRibbonA(control As IRibbonControl)
    MsgBox "OK"
End Sub

'Callback for data2 onAction
Sub IRibbonB(control As IRibbonControl)
    MsgBox "OK"
End Sub

' 工作表激活事件,当工作表激活时确定按钮是否可用
Private Sub xlApp_SheetActivate(ByVal Sh As Object)
    On Error Resume Next
    RedoMailRib
End Sub

Sub RedoMailRib()
    On Error Resume Next
    MailRib.Invalidate
End Sub
Customize RibbonX UI.rar (8.9 KB, 下载次数: 39)
回复

使用道具 举报

发表于 2012-1-27 19:32 | 显示全部楼层
在该按钮中加上这个代码:
......
If IsEmpty(ActiveSheet.UsedRange) Then MsgBox "空表":exit sub
......

不必另行隐藏按钮吧!
回复

使用道具 举报

 楼主| 发表于 2012-1-30 16:36 | 显示全部楼层
如果能实现区域的动态可用性,交互效果要好一些
回复

使用道具 举报

发表于 2012-2-1 11:37 | 显示全部楼层
附件包含两个文件,一个是customUI.xml,另一个是要加载的COM加载项,两文件放于同一文件夹,然后加载COM加载项 qq.rar (6.75 KB, 下载次数: 43)
回复

使用道具 举报

 楼主| 发表于 2012-2-4 09:18 | 显示全部楼层
吕?布 发表于 2012-2-1 11:37
附件包含两个文件,一个是customUI.xml,另一个是要加载的COM加载项,两文件放于同一文件夹,然后加载COM加 ...

谢谢吕布,呵呵
回复

使用道具 举报

发表于 2012-2-7 08:21 | 显示全部楼层
没人要源码
回复

使用道具 举报

 楼主| 发表于 2012-2-10 08:47 | 显示全部楼层
非常感谢吕布的源码
回复

使用道具 举报

发表于 2012-2-10 12:47 | 显示全部楼层
太深奥了!


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-6-1 07:57 , Processed in 0.323741 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表