使用C#以编程方式将VB函数设置为oleobject [英] Set VB function to the oleobject programmatically using C#
问题描述
我正在做PowerPoint加载项.我有自己的自定义对象(作为Activex创建的OLEObject),该对象通过开发人员"选项卡中的添加OLE对象选项"导入到PowerPoint中.通过从ole对象集合中选择此对象,我可以将该自定义对象放置到PowerPoint幻灯片中.然后,通过双击该对象,可以为此对象设置VBA处理程序函数,例如onClick,并且可以在此VB函数主体中编写任何自定义代码来满足我的要求(例如,显示一个消息框).我的问题是,是否可以通过编程方式完成将VB功能设置为OLE对象单击"的上述过程? IE.单击PowerPoint中的自定义菜单项或功能区按钮时,我需要为OLE对象设置VB处理函数.
我尝试了使用代码
将VBA函数以编程方式导入PowerPoint的方法
"prez.VBProject.VBComponents.Import("D:\\ ModuleFile.bas");"
然后为ole对象设置动作动词,如下所示.
MyCustomObject.ActionSettings [PowerPoint.PpMouseActivation.ppMouseClick] .ActionVerb ="onMyObjectClick";
但是通过使用这一行代码,我收到了一个错误无法将操作设置应用于此形状"
帮助我解决此问题或提供其他任何方法来做同样的事情.
在此先感谢…
I am doing PowerPoint add-in. I have my own custom object (an OLEObject created as Activex) which is imported to the PowerPoint by the "Add OLE object option" available in the "Developer" tab. I am able to place this custom object to a PowerPoint slide by selecting this object from the ole object collection. Then by double clicking on the object, I can set the VBA handler function for this object such as onClick, and I can write any custom code in this VB function body for meeting my requirement (say show a message box). My question is whether it is possible to do the above process of "setting a VB function to the OLE object click" programmatically? I.e. I need to set the VB handler function for the OLE object while clicking a custom menu item or ribbon button in PowerPoint.
I tried the approach of importing the VBA function to PowerPoint programmatically using the code
"prez.VBProject.VBComponents.Import("D:\\ModuleFile.bas");"
and then setting the action verb for the ole object as given below.
MyCustomObject.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick].ActionVerb = "onMyObjectClick";
But by using this line of code, I got an error "cannot apply action settings to this shape"
Help me to resolve this problem or give any other method to do the same.
Thanks in advance…
推荐答案
希望您从StackOverFlow的 ^ ]
Hope you got the solution from StackOverFlow at http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/08131937-9cf7-435f-aef5-1766bfad4787[^]
这篇关于使用C#以编程方式将VB函数设置为oleobject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!