I am trying to automate at first glance a very simple task via C# - to pass a string value to an inputBox called through VBA function.
In order to do that I have used Visual C# .NET Automation Client to create an instance of MS Access and open the required database:
using System.Management.Automation;
using Access = Microsoft.Office.Interop.Access;
Access.Application oAccess = new Access.Application();
oAccess.Visible = true;
oAccess.OpenCurrentDatabase("D:\\path\\to\\database", false, "");
In the mentioned database we have a Macro that calls a VBA function via the "RunCode" action. This public Function then calls another private Sub:
Public Function ImportMappingDatabases()
ImportMappings InputBox("Specify Path", "Path", mstrcDefaultPath), _
InputBox("Choose Package", "Package", "")
End Function
Private Sub ImportMappings(Optional Path As String = mstrcDefaultPath, Optional Package As String = "")
Here is where I got stuck. The input box with the title "Path" wants the user to input a certain path that the later code uses for reasons that do not need to be explained. The same is valid for the input box with the title "Package". I assume there is a way to "pass" a string value from the C# code to the input box entry field, but I do not know how to refer to the input box and set the value. After that is done the user is required to click on the "OK" button or the "Cancel", the same question applies, I will try to synthesize it in 1 sentence:
How to get a reference of that input box, set the input value, and "click" one of the buttons?
More information:
I am calling the public function via: oAccess.Run("ImportMappingDatabases");
I can not modify the VBA functions/subs.
Update 1:
Check my answer below.
oAccess.Run "ImportMappingDatabases", varInput;I don't use macros. - June7