I am fairly new to C# and VBA coding so bear with me I don't know what is necessary information and what is not. Anyway, I am trying to create a VSTO add-in for Word using C# in Visual Studio that essentially has a few buttons that run VBA macros when clicked. I have followed searched for solutions, but most apply to excel and don't seem to exactly solve my issue, the closest I can find is this previous question (How-to: Run existing Word VBA Macros from C# Ribbon Addin) but the solution did not resolve my issue.
So I have the Macro in a document, that works as expected if I run it directly from the document (there are no arguments for the macro code). I have the buttons created and the add-in ribbon appears when I open an instance of Word. I also have the following methods in my addin.cs file:
private void RunMacro(object oApp, object[] oRunArgs)
{
oApp.GetType().InvokeMember("Run",
System.Reflection.BindingFlags.Default |
System.Reflection.BindingFlags.InvokeMethod,
null, oApp, oRunArgs);
}
and the following method as the call onAction for the one button (say Button1)
public void OnButton1(Office.IRibbonControl control)
{
RunMacro(Globals.ThisAddIn.Application, new object[] {"Button1Macro"});
}
Any help would be greatly appreciated. Thanks