• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 468
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

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