Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there tool that can port or compile excel VBA code to C#?

I don't know much about .net, but I am working on a project where a requirement is to port some Excel VBA code embedded in spreadsheets to standalone C# .

Are they any tools that could automate (or semi-automate) this port or compile? How well do they work?

like image 875
DanSingerman Avatar asked Feb 28 '23 11:02

DanSingerman


2 Answers

No. Your best bet, if it's not alot of code is to do it by hand.

Otherwise, you mileage might vary. You might try converting the VBA to VB.NET and then use a tool to convert that to C#.

Converting Code from VBA to Visual Basic .NET

Ten Code Conversions for VBA, Visual Basic .NET, and C#

like image 125
Mitch Wheat Avatar answered Mar 05 '23 14:03

Mitch Wheat


This is an old thread, but thought I would complete it as I :

Case 1: Converting VB to C#

If you need to convert your code to C# use Telerik's web code converter: http://converter.telerik.com/. Simply paste your VBA code (make sure you are not using Excel specific functions or variables like Range, Worksheets etc.) and convert. You should be able to easily re-use the code in your C#.NET project in Visual Studio.

If you want to make the library re-usable in Excel (make it COM-visible) check-out this post here.

Case 2: Converting VBA to VB.NET

If you don't need to make the DLL COM-visible simply create a VB.NET project in Visual Studio, compile and fix any found compilation errors :).

Otherwise, if want the DLL to be automated directly from Excel - I recently created an Add-In that does just that. It creates a COM-visible DLL directly from your Workbook (just select your VBA Functions) and pastes the required load procedures into your workbook as well. Find it here.

like image 27
AnalystCave.com Avatar answered Mar 05 '23 14:03

AnalystCave.com