Question: Let's say I want to find the value of a cell in an Excel file. In VBA, I would do this:

```
Dim varValue As Variant
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Sheet1")
varValue = ws.Range("A1").Value

```

How do I set up a Visual Studio project so I can access and modify an Excel file in C# rather than in VBA?

What references might I need to add?

Does the file need to be open in order to work with it?

Answer: 
You can use Excel automation or a third-party library.

To use Excel automation, you should install the Office PIAs and add a reference to `Microsoft.Office.Interop.Excel.dll`. You would then write code to open the file (using the `ApplicationClass` class) and manipulate it. 

This approach would use the same object model that you're used to in VBA. However, since C# 3 does not support optional parameters or weak typing, it will be somewhat annoying. It would be easier to do it in VB .Net or C# 4 (currently in beta)

---

Excel automation is not suitable for code running in non-interactive context. There are a number of third-party libraries written entirely in .Net that can read and write Excel files.

In addition, if you only need to manipulate table-like data, you can use OleDb to run SQL statements against Excel files using [this connection string](http://www.connectionstrings.com/excel).

You can use [`OleDbCommand`](http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.aspx)s to run `SELECT * FROM [SheetName]`, assuming that the sheet is a table. You can also select from a named range. You can get the available tables by calling [`oleDbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null)`](http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection.getoledbschematable.aspx) and looking at the `TABLE_NAME` column ion the returned DataTable.
You have to used Microsoft.Office.Interop.Excel.
You'll need to use COM Interop. [Here's](http://msdn.microsoft.com/en-us/library/ms173186(VS.80).aspx) a detailed tutorial about how it's done.