Solved

How to launch VBA code from C#

Posted on 2008-10-10
3
452 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is newest platform to convert a massive Windows Forms program to? 7 53
Securing WEBAPI on Azure 2 28
C# Windows Form Navigation - Total Beginner 9 54
C# LINQ 5 28
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

696 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