The following example demonstrates how to run a user-defined VBA (Visual Basic for Applications) macro (in the RC-WinTrans 9 VBA environment) from a COM automation client developed in C# (.NET).
The C# client has an edit field where a message text can be entered. The C# application calls (on command) a VBA macro passing the message text as a parameter. The VBA macro writes the message text to RC-WinTrans' Output window.
If RC-WinTrans is not already running, the C# client will start it.
Program type: EXE, COM automation client Software platform: Microsoft .NET 1.1 Programming language: C# Development environment: Microsoft Visual Studio .NET 2003
The sample program has a reference to RC-WinTrans' type library. The RC-WinTrans application ("RCWinTrans.Application") will be created with the new operator.
The program's source code file ("Form1.cs") contains the implementation of the sample code. The programming code contains several comments/descriptions.
The VBA macro is called via an RC-WinTrans COM object called "VBATool." This object has two methods ("RunFunction" and "RunMacro") to call any VBA function and/or any VBA procedure.
Starting RC-WinTrans (file: "Form1.cs"):
Preparing the parameters and a parameters array passed to the VBA macro, and calling the VBA using the RC-WinTrans COM object "VBATool" (file: "Form1.cs"). Two parameters (a string and a boolean value) are passed to the VBA macro that's called.
The example includes the VBA macros file containing a macro named "WriteToOutputWindow," that is called by the sample application.
The macros file was initially created with RC-WinTrans and the macro was coded using the Microsoft VBA editor in RC-WinTrans.
To demonstrate the passing of parameters to a macro and retrieving a return value, "WriteToOutputWindow" is a VBA function which has two parameters and a return value.
Enabling the Macros File The macros file must be added to (i.e., enabled for use in) RC-WinTrans. You can do this in one of two ways:
NOTE: RC-WinTrans will ask you to copy the macros file to the default folder for macros files in the RC-WinTrans installation directory. Close the message box with "No" to not make a copy of the macros file and use the file in the sample directory.
Once the macros file is added to RC-WinTrans the sample program can be run.
The VBA function "WriteToOutputWindow" (file: "CSharpClient.macro"):
You can use the VBA debugger to set a breakpoint into the VBA function to see when the macro is being called and executed.
Procedure:
|