Solved

How to launch VBA code from C#

Posted on 2008-10-10
3
453 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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