Dim WB As Microsoft.Office.Interop.Excel.Workbook = Globals.ThisAddIn1.Application.ActiveWorkbook Dim dt As New System.Data.DataTable() Dim strWorkbookName As String Dim strConn As String Dim strExcelSheet As String Dim xlConn As OleDbConnection Try WB.SaveAs("myWorkBook_" + DateTime.Now.ToString("yyyyMMdd_HHmmss")) strWorkbookName = WB.FullName (here I get the full path of my saved excel workbook) strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strWorkbookName + ";Extended Properties='Excel 12.0 Xml;HDR=Yes;IMEX=1'" xlConn = New OleDbConnection(strConn) xlConn.Open() dt = xlConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing) If dt IsNot Nothing OrElse dt.Rows.Count > 0 Then strExcelSheet = dt.Rows(0)("table_name").ToString() Dim da As New OleDbDataAdapter("SELECT * FROM ["+strExcelSheet +"]", xlConn) da.Fill(dsSave, strExcelSheet) End If Catch ex As Exception MsgBox("Error"+ ex.Message.ToString()) Finally xlConn.Close() End Try
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)