0

I have a VBA macro that I am trying to convert to C#. I am having trouble linking to the excel application and using the excel commands.

Below is a piece of the code I am trying to convert.

Dim myExcel As Excel.Application 
Dim mySheet As Worksheet 
Dim myWorkbook As Workbook
Dim FilePath As Variant
Dim myFile As Variant

Set myExcel = GetObject(, "Excel.Application")
Set mySheet = myExcel.Worksheets("sheetname")

I have tried adding the reference to Microsoft.Office.Interop.Excel but cannot find the how a reference a particular sheet or cell in a sheet. I am trying to learn C#,

so your patience is very much appreciated along with any help.

0m3r
  • 12,286
  • 15
  • 35
  • 71
spaseur
  • 1
  • 2
  • 1
    you reference a particular sheet or cell in a sheet in the same way regardless of vba or C# (except maybe '(' becomes '[' ). Plese show your attempt. If want you want to do is manipulate excel from C# then look at EppPlus – Mitch Wheat Mar 19 '17 at 03:28
  • 1
    Possible duplicate of [How to open an Excel file in C#?](http://stackoverflow.com/questions/464902/how-to-open-an-excel-file-in-c) – Richard Schwartz Mar 19 '17 at 04:01
  • 1
    `Dim myExcel As Excel.Application` = `Excel.Application myExcel;` & `Set myExcel = GetObject(, "Excel.Application")` = `SetmyExcel = GetObject(,, "Excel.Application");` – 0m3r Mar 19 '17 at 04:20
  • Is this vsto? winform? – Jeremy Thompson Mar 19 '17 at 10:36

0 Answers0