Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

How do I read/write Excel cell data to textbox & visaversa

Well since you're copying data from the worksheet, I'm guessing its not a "new" worksheet.
But you have to declare the application, workbook, and worksheet that you are trying to get
data from
Code:
Dim excelApp As New Microsoft.Office.Interop.Excel.Application
Dim excelBook As Microsoft.Office.Interop.Excel.Workbook
Dim excelSheet As Microsoft.Office.Interop.Excel.Worksheet
excelBook = excelApp.Workbooks.Open("path")
excelSheet = excelBook.Worksheets(1)
'Now that you have your worksheet you can do your data manipulation
Textbox1.Text = excelSheet.Range("A1").Text
'or to edit
excelSheet.Range("A1").Text = Textbox1.Text
excelBook.Close
excelApp.Close

excelBook2 = new Excel.Workbook


excelsheet = excelBook2.Worksheets(1)
'I think it should already have 3 worksheets, thats why I set the worksheet to the
first worksheet in the new workbook.
'Add your changes
Textbox1.Text = excelSheet.Range("A1").Text
excelBook2.Close(SaveChanges:=True)

You might also like