amado first

amado first

  • NA
  • 5
  • 29.1k

How to export data from visual studio 2012 to excel sheet?

Jan 8 2014 3:57 PM
I am using visual studio express 2012, 

i have created a Vb calculation application (outputs based on variable inputs) & i need to save these input and output data to excel file each time i click save. 

More Details


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim xls As Microsoft.Office.Interop.Excel.Application
Dim xlsWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlsWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value

xls = New Microsoft.Office.Interop.Excel.Application
xlsWorkBook = xls.Workbooks.Open("D:\bookl.xlsx")
xlsWorkSheet = xlsWorkBook.Sheets("sheet1")

xlsWorkSheet.Cells(1, 1) = TextBox1.Text

xlsWorkBook.Close()
xls.Quit()

End Sub


my problem here is that in every time i click the save button it saves the data to a excel sheet file which i have to specify its path previously.

What i wish to do is if there is any way to load from VB it self then choose where to save it (because iam going to use it in a lot of machines, so i don't want to put the excel file in the same path each time i use the application in any other machine)

Answers (6)