Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从功能区按钮调用Excel宏_C#_Xml_Excel_Vsto_Ribbon - Fatal编程技术网

C# 从功能区按钮调用Excel宏

C# 从功能区按钮调用Excel宏,c#,xml,excel,vsto,ribbon,C#,Xml,Excel,Vsto,Ribbon,我有一个VBA宏,它通过一个按钮在excel中完美地工作,但我想在excel功能区中包含一个按钮(我已经这样做了),但我不知道如何将功能区按钮正确地连接到宏,以下是我的C#和XML代码: C# XML 这将从当前打开的excel工作簿运行宏,或从xlstart(C:\Users\\AppData\Roaming\Microsoft\excel\xlstart)文件夹中可用的工作簿运行宏 Globals.ThisWorkbook.Application.Run("Your macroname")

我有一个VBA宏,它通过一个按钮在excel中完美地工作,但我想在excel功能区中包含一个按钮(我已经这样做了),但我不知道如何将功能区按钮正确地连接到宏,以下是我的C#和XML代码:

C#

XML


这将从当前打开的excel工作簿运行宏,或从xlstart(C:\Users\\AppData\Roaming\Microsoft\excel\xlstart)文件夹中可用的工作簿运行宏

 Globals.ThisWorkbook.Application.Run("Your macroname")

似乎无法使其工作,xlstart文件夹是否存在?我没有使用customUI编辑器宏在哪里?是否在通过添加功能区控件进行自定义的同一文档中?只需将宏名称作为参数传入ribbon.xml中的参数onAction=“'PM MailMerge.xlsm'!MailMerge.MailMerge”必须是onAction=“button1\u onAction”在button1\u onAction方法上添加try catch,并查找是否存在任何异常。
<?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2009/07/customui" >
<ribbon>
<tabs>
  <tab  id="TimerTest" 
        label="Practice Monitoring">
    <group  id="group1" 
            label="MailMerge">
      <labelControl id="timerLabel" 
                     getLabel="timerLabel_getLabel"/>
      <button   id="button1" 
                label="Merge" 
                size="large" 
                onAction="'PM MailMerge.xlsm'!MailMerge.MailMerge"/>
    </group>
  </tab>
</tabs>
</ribbon>
</customUI>
 Globals.ThisWorkbook.Application.Run("Your macroname")