[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 459
  • Last Modified:

How to launch VBA code from C#

We are converting some of our reporting code and need to be able to open an Excel template (got that) and then launch a VBA code in that template, and pass a parameter. Later on we will be replacing all the VBA code, but for now I just want to fire it.
0
leonstryker
Asked:
leonstryker
1 Solution
 
RishadanPortCommented:
1. Create a dll using the VBA Code
2. Add this DLL as a reference to your C# code
3. Call the function you want
0
 
Wayne Taylor (webtubbs)Commented:
Hi leonstryker,

To run VBA present in a Workbook, use somthing like this....

    xlApp.Run("'" + xlWB.Name + "'!MacroName", "Param1", "Param2");

...where xlApp is the Excel Application object and xlWB is the Workbook object. The Run method allows up to 30 parameters.

Regards,

Wayne
0
 
leonstrykerAuthor Commented:
Sorry RishadanPort, but the idea is to run the current code which already exist in VBA

Thanks Wayne, I will give it a try on Monday and let you know.

Leon
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now