从VSTO PowerPoint功能区调用VBA加载宏 [英] Call VBA AddIn macro from VSTO PowerPoint Ribbon

查看:235
本文介绍了从VSTO PowerPoint功能区调用VBA加载宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这个问题上停留了几个小时:



我正在用C#开发一个PowerPoint插件,我想使用另一个插件中的宏是PPAM文件。 PPAM文件已安装并启用。



在应用程序参考中,我发现我需要使用 Application.Run 方法,但我无法使其正常工作(什么都没发生)...这是我的代码:

  Globals.ThisAddIn.Application.Run( PPspliT.ppam!PPspliT.PPspliT_main,null); 

PPspliT.ppam 是已安装的AddIn( 位于以下位置: C:\Users\XXXX\AppData\Roaming\Microsoft\AddIns\PPspliT\



调用 PPspliT_main 宏的模块名为 PPspliT



我发现另一件事很奇怪,即使宏没有任何参数,Run也需要接受两个参数(这就是为什么将空值作为第二个参数)。



我也尝试使用以下方式以编程方式安装AddIn:



< pre class = lang-cs prettyprint-override> String addinPath = @ C:\Users\XXXXX\AppData\Roaming\Microsoft\AddIns\PPspliT;
var macroFilePath = Path.Combine(addinPath, PPspliT.ppam);
var addins = Globals.ThisAddIn.Application.AddIns.Add(macroFilePath);
if(!(addins.Registered == MsoTriState.msoTrue&& addins.Loaded == MsoTriState.msoTrue)))
{
addins.Registered = MsoTriState.msoTrue;
addins.Loaded = MsoTriState.msoTrue;
}
var app = Globals.ThisAddIn.Application;
string macroToInvoke = string.Format( {0}!{1}, PPspliT.ppam, PPspliT.PPspliT_main);
Globals.ThisAddIn.Application.Run(macroToInvoke,null);

感谢您的帮助!
Acacio

解决方案

这件事使我发疯,但我发现了如何使其正常工作!这就是我所做的(使用此 http://support.microsoft.com/kb/306682



因此,正如我在问题中解释的那样,我首先以编程方式注册并加载了加载项,然后执行以下操作:

 私有无效RunMacro(object oApp,object [] oRunArgs)
{
oApp.GetType()。InvokeMember( Run,
System.Reflection.BindingFlags.Default |
System.Reflection.BindingFlags.InvokeMethod,
null,oApp,oRunArgs);
}

Globals.ThisAddIn.RunMacro( Globals.ThisAddIn.Application,new object [] { PPspliT_main});

感谢大家您的帮助!


I've been stuck for a few hours on this problem :

I am developing a PowerPoint AddIn in C# and I want to use a macro from another AddIn which is a PPAM file. The PPAM file is installed and enabled.

In the Application reference I found that I need to use the Application.Run method but I cannot get it working (nothing happens)... Here is my code:

Globals.ThisAddIn.Application.Run("PPspliT.ppam!PPspliT.PPspliT_main", null);

PPspliT.ppam is the installed AddIn (which is located here : C:\Users\XXXX\AppData\Roaming\Microsoft\AddIns\PPspliT\)

The module in which the PPspliT_main macro is called is named PPspliT.

Another thing I find strange is that Run needs to take two arguments even if the macro doesn't have any argument (that's why I put null as second argument).

I also tried to install the AddIn programmatically using this :

String addinPath = @"C:\Users\XXXXX\AppData\Roaming\Microsoft\AddIns\PPspliT";
var macroFilePath = Path.Combine(addinPath, "PPspliT.ppam");
var addins = Globals.ThisAddIn.Application.AddIns.Add(macroFilePath);
if (!(addins.Registered == MsoTriState.msoTrue && addins.Loaded == MsoTriState.msoTrue))
{
  addins.Registered = MsoTriState.msoTrue;
  addins.Loaded = MsoTriState.msoTrue;
}
var app = Globals.ThisAddIn.Application;
string macroToInvoke = string.Format("{0}!{1}", "PPspliT.ppam", "PPspliT.PPspliT_main");
Globals.ThisAddIn.Application.Run(macroToInvoke, null);

Thanks for your help! Acacio

解决方案

This thing was driving me crazy but I found how to get it working ! Here is what I did (using this http://support.microsoft.com/kb/306682 :

So as I explained in my question I first programmatically register and load the add-in then I do the following :

    private void RunMacro(object oApp, object[] oRunArgs)
    {
       oApp.GetType().InvokeMember("Run",
       System.Reflection.BindingFlags.Default |
       System.Reflection.BindingFlags.InvokeMethod,
       null, oApp, oRunArgs);
    }

Globals.ThisAddIn.RunMacro(Globals.ThisAddIn.Application , new object[] {"PPspliT_main"});

Thanks to everyone for your help !

这篇关于从VSTO PowerPoint功能区调用VBA加载宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆