![](/uploads/1/2/5/5/125511294/851624057.jpg)
Instead of putting this code in a standard module, you'll have to put it in the ThisWorkbook object of the workbook you want it in (in the 'Microsoft Excel Objects' folder). Just set the name of the worksheet at the.
.NET 4+ allows C# to read and manipulate Microsoft Excel files, for computers that have Excel installed (if you do not have Excel installed, see NPOI).
First, add the reference to Microsoft Excel XX.X Object Library, located in the COM tab of the Reference Manager. I have given this the using alias of Excel.
Next, you'll need to create references for each COM object that is accessed. Each reference must be kept to effectively exit the application on completion.
![Using.com objects in perl Using.com objects in perl](/uploads/1/2/5/5/125511294/772564203.png)
Then you can read from the sheet, keeping in mind that indexing in Excel is not 0 based. This just reads the cells and prints them back just as they were in the file.
Lastly, the references to the unmanaged memory must be released. If this is not properly done, then there will be lingering processes that will hold the file access writes to your Excel workbook.
![Objects Objects](/uploads/1/2/5/5/125511294/387582241.png)
Further reading:
Full Code:
![](/uploads/1/2/5/5/125511294/851624057.jpg)