vb.net - Prevent Excel pop up message in VB code -
i having problem "file available" message box popping open excel when importing file program.
http://oi50.tinypic.com/23wajt.jpg
private function xlsselect_click(strfilename string) datatable dim connectionstringtemplate string = "provider=microsoft.ace.oledb.12.0;" + "data source={0};" + "extended properties=""excel 12.0;hdr=yes;imex=1""" dim connectionstring string = string.format(connectionstringtemplate, strfilename) try dim sqlselect string = "select * [" & getexcelsheetnames(strfilename)(0) & "];" ' load excel worksheet datatable dim workbook dataset = new dataset() dim exceladapter system.data.common.dataadapter = new system.data.oledb.oledbdataadapter(sqlselect, connectionstring) exceladapter.fill(workbook) integer = 0 workbook.tables(0).columns.count - 1 workbook.tables(0).columns(i).columnname = workbook.tables(0).columns(i).columnname.tostring.trim.replace(" ", "") next return workbook.tables(0).copy catch throw new exception("error reading excel spreadsheet. sure file isn't open in excel, , has been saved .xls through excel @ least once?") end try return nothing end function private shared function getexcelsheetnames(excelfile string) [string]() dim objconn oledbconnection = nothing dim dt system.data.datatable = nothing try dim connstring [string] = "provider=microsoft.ace.oledb.12.0;" & "data source=" & excelfile & ";extended properties=excel 12.0;" ' create connection object using preceding connection string. objconn = new oledbconnection(connstring) ' open connection database. objconn.open() ' data table containg schema guid. dt = objconn.getoledbschematable(oledbschemaguid.tables, nothing) if dt nothing return nothing end if dim excelsheets [string]() = new [string](dt.rows.count - 1) {} dim integer = 0 'add sheet name string array. each row datarow in dt.rows excelsheets(i) = row("table_name").tostring() += 1 next return excelsheets catch ex exception return nothing ' clean up. if objconn isnot nothing objconn.close() objconn.dispose() end if if dt isnot nothing dt.dispose() end if end try end function
anyone know how can go disabling ?
dim appexcel excel.application set appexcel = new excel.application appexcel.workbooks.open "e:\development\test.xls", 0 ' thing here... appexcel.displayalerts = false ' surpress save dialog box. appexcel.quit ' quit without saving. can change want set appexcel = nothing
in code
try dim connstring [string] = "provider=microsoft.ace.oledb.12.0;" & "data source=" & excelfile & ";extended properties=excel 12.0;" ' create connection object using preceding connection string. objconn = new oledbconnection(connstring) ' open connection database. objconn.open()
appexcel.displayalerts = false ' try here!
' data table containg schema guid. dt = objconn.getoledbschematable(oledbschemaguid.tables, nothing)
sources : http://www.xtremevbtalk.com/showthread.php?t=16007
Comments
Post a Comment