Solved

How to launch VBA code from C#

Posted on 2008-10-10
3
449 Views
Last Modified: 2013-12-17
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
Comment
Question by:leonstryker
3 Comments
 
LVL 6

Expert Comment

by:RishadanPort
ID: 22691088
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
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 22692250
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
 
LVL 29

Author Comment

by:leonstryker
ID: 22692715
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now