3

Is there any way to run Excel macro from C# .Net without installing Excel?

Currently I am running a macro using Excel Microsoft.Office.Interop.Excel which requires Excel to be installed on the server machine. There are some libraries such as NPOI which can be used for reading or writing Excel but not sure whether it is possible to run the macro using such libraries without installing Excel.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
parag
  • 2,483
  • 3
  • 20
  • 34

1 Answers1

3

You cannot run a macro/VBA directly without installing Excel.

But there are some .NET libraries that can read Excel files (as you already found out). But you will need to convert/translate your macro/VBA code into a C#.NET code that uses the library.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • As stated in this comment: [Writing and Executing VBA Macros on Excel without using Excel.Interop [duplicate]](https://stackoverflow.com/a/33394932/642771) you can add VBA code to en Excel Workbook if using EPPlus (at least version 4.0.4). The example adds the code to de Open method, so it is automatically run when you open the workbook. The con is that it will run depending on the macro execution config. – EAmez Aug 28 '18 at 09:14