Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
How to read cell(1,1) and cell(1,2) from an excel workbook (c:/add.xls); worksheet (sheet1) and add the two numbers and display output in excel sheet (sheet 2 of c:/add.xls) cell(1,1)?
Posted

Use the following line to open an Excel application:

Dim Xl As New Excel.Application()

 

Use the following line to open an Excel file (abc.xls)

Dim Xlb As Excel.Workbook = Xl.Workbooks.Open(abc.xls)

 

Use the following line to connect to Sheet1:

Dim Xls As Excel.Worksheet = CType(Xlb.Worksheets(1), Excel.Worksheet)

 

Use the following line to connect to Sheet2:

Dim Xlsa As Excel.Worksheet = CType(Xlb.Worksheets(2), Excel.Worksheet)

 

 

Use the following line to copy from Sheet1: A1 to Sheet2: A2

xlsa.cells(1,1).value=xls.cells(1,1).value

 

Hope this helps. Don't forget to close files and application. Good luck.

Posted

For the example I gave earlier, you can use the following to close the file, quit application, and free objects.

 

Xlb.Close(False)

Xl.Application.Quit()

Xl = Nothing

Xlb = Nothing

Xls = Nothing

Xlsa=Nothing

 

Good Luck.

  • 6 years later...
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...