I am trying to open a Word document from a C# app, insert a macro, run it, then close. The problem I am running into is
Compile Error: Argument not optional
I've been looking at this article but I am not returning anything. Not seeing what I am missing here.
Here is the debugger:
Here is the C# code:
Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application();
newApp.Visible = true;
object Unknown = Type.Missing;
var Source = fileName;
var doc = newApp.Documents.Open(Source);
var project = doc.VBProject;
var module = project.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule);
var macro = "Public Sub DoKbTest()\r\n" +
"MsgBox 'Hello'\r\n" +
"End Sub\r\n" +
"Public sub DoKbTestWithParameter(sMsg As String)\r\n" +
"MsgBox sMsg\r\n" +
"End Sub";
module.CodeModule.AddFromString(macro);
newApp.Run("DoKbTest");
newApp.Quit(ref Unknown, ref Unknown, ref Unknown);