Excel精英培训网

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

求围观:excel文件自定义customUI回调如何引用com加载宏

[复制链接]
发表于 2013-8-22 10:46 | 显示全部楼层 |阅读模式
本帖最后由 nienie2010 于 2013-8-22 19:36 编辑

excel 文件中自定义customUI,回调onaction,不能响应com加载宏。com能正常加载,但不能响应,请老师们赐教,谢谢!

附件.rar

24.42 KB, 下载次数: 13

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2013-8-22 10:57 | 显示全部楼层
回复

使用道具 举报

 楼主| 发表于 2013-8-22 11:49 | 显示全部楼层
我心飞翔410 发表于 2013-8-22 10:57
http://www1.huachu.com.cn/read/readbookinfo.asp?sectionid=1000001709

我在com加载宏中connection中代码加入
Option Explicit
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)
    On Error Resume Next
    Set xlApp = Nothing
End Sub
Public Function AA(ByVal control As IRibbonControl)
MsgBox "数据", vbInformation
End Function

customUI自定义一个<button id="customButton2" label="数据" size="large"
1、能正常加载
2、但是onAction却不响应AA这个函数??
回复

使用道具 举报

发表于 2013-8-22 11:52 | 显示全部楼层
意思自定义一个菜单不响应 那就是程序调用不对了
回复

使用道具 举报

 楼主| 发表于 2013-8-22 11:52 | 显示全部楼层
我心飞翔410 发表于 2013-8-22 10:57
http://www1.huachu.com.cn/read/readbookinfo.asp?sectionid=1000001709

我在com加载宏中connection中代码加入
Option Explicit
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)
    On Error Resume Next
    Set xlApp = Nothing
End Sub
Public Function AA(ByVal control As IRibbonControl)
MsgBox "数据", vbInformation
End Function

customUI自定义一个<button id="customButton2" label="数据" size="large"
1、能正常加载
2、但是onAction却不响应AA这个函数??

回复

使用道具 举报

 楼主| 发表于 2013-8-22 11:55 | 显示全部楼层
我心飞翔410 发表于 2013-8-22 11:52
意思自定义一个菜单不响应 那就是程序调用不对了

那怎么调用呢?应该onAction可以相应“AA”啊。如果把
Public Function AA(ByVal control As IRibbonControl)
MsgBox "数据", vbInformation
End Function

放到excel的VBE代码中时可以正常运行的。但是用com加载宏就不行了?这个怎么解决,请帮我解决下,谢谢!

点评

给事要用UI工具 回调程序  发表于 2013-8-22 12:16
回复

使用道具 举报

 楼主| 发表于 2013-8-22 16:33 | 显示全部楼层
我心飞翔410 发表于 2013-8-22 11:52
意思自定义一个菜单不响应 那就是程序调用不对了

谢谢回复,我刚刚做好了附件,请帮我修改下,看怎么能回调,谢谢!
回复

使用道具 举报

发表于 2013-8-22 16:42 | 显示全部楼层
'Callback for customButton1 onAction
Sub AA(control As IRibbonControl)
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)
    On Error Resume Next
    Set xlApp = Nothing
End Sub
Public Function AA(ByVal control As IRibbonControl)
MsgBox "数据", vbInformation
End Sub
回复

使用道具 举报

发表于 2013-8-22 16:43 | 显示全部楼层
'Callback for customButton1 onAction
Sub AA(control As IRibbonControl)
  代码区  你在试试
End Sub
另外存为 xlsm格式 不是xlsx格式
回复

使用道具 举报

 楼主| 发表于 2013-8-22 16:55 | 显示全部楼层
我心飞翔410 发表于 2013-8-22 16:42
'Callback for customButton1 onAction
Sub AA(control As IRibbonControl)
AddInDesignerObjects.ext_C ...

您好!
我按你的代码将代码修改,不能通过程序检查。能麻烦您把修改后的附件回传下吗?谢谢!
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-23 02:23 , Processed in 5.569490 second(s), 17 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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