hi all! i have here a code for browse button
and for view button
everytime i hit the view button a message box comes out saying exception HResult 0x800A01A8 also the excel file opens. i dont want the excel file to be opened please help
VB.NET:
[LIST=1]
[*]Private Sub btnbrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbrowse.Click
[*]
[*] 'prompt user to select Excel name and folder path
[*]
[*] Dim openFileDialog1 As System.Windows.Forms.OpenFileDialog
[*] openFileDialog1 = New System.Windows.Forms.OpenFileDialog
[*]
[*] With openFileDialog1
[*] .Title = "Excel Spreadsheet"
[*] .FileName = ""
[*] .DefaultExt = ".xls"
[*] .AddExtension = True
[*] .Filter = "Excel Worksheets|*.xls; *.xlsx"
[*]
[*] If .ShowDialog = Windows.Forms.DialogResult.OK Then
[*] excelPathName = (CType(.FileName, String))
[*]
[*] If (excelPathName.Length) <> 0 Then
[*] Me.TextBox1.Text = excelPathName
[*] Else
[*]
[*] End If
[*] End If
[*] End With
[*]
[*] End Sub
[/LIST]
VB.NET:
[LIST=1]
[*] 'test open up excel spreadsheet
[*] Dim objExcel As New Excel.Application
[*] Dim objBook As Excel.Workbook = objExcel.Workbooks.Open(excelPathName)
[*] Dim objSheet As Excel.Worksheet = objBook.Worksheets(1)
[*] objExcel.Visible = True
[*] Dim bolFlag As Boolean = True
[*] Dim excelRow As Integer = 7
[*] Dim excelCol As Integer = 1
[*] Dim DGVRow As Integer = 1
[*] Dim strCell1 As String
[*] Dim strCell2 As String
[*] Dim strCell3 As String
[*] Dim strCell4 As String
[*] Dim strCell5 As String
[*] Dim strCell6 As String
[*] Try
[*] Do While bolFlag = True
[*]
[*] If Convert.ToString(objSheet.Cells(excelRow, 1).value) = "" Then
[*] bolFlag = False
[*] Exit Do
[*] End If
[*]
[*] With DataGridView1
[*]
[*] strCell1 = CType(objSheet.Cells(excelRow, 1).value, String)
[*] strCell2 = CType(objSheet.Cells(excelRow, 2).value, String)
[*] strCell3 = CType(objSheet.Cells(excelRow, 3).value, String)
[*] strCell4 = CType(objSheet.Cells(excelRow, 4).value, String)
[*] strCell5 = CType(objSheet.Cells(excelRow, 5).value, String)
[*] strCell6 = CType(objSheet.Cells(excelRow, 6).value, String)
[*]
[*] DGVRow += 1
[*] excelRow += 1
[*]
[*] strCell1 = ""
[*] strCell2 = ""
[*] strCell3 = ""
[*] strCell4 = ""
[*] strCell5 = ""
[*] strCell6 = ""
[*] End With
[*] Loop
[*] Catch ex As Exception
[*] MessageBox.Show(ex.Message)
[*] Finally
[*] objBook.Close()
[*] objExcel.Quit()
[*] End Try
[*] End Sub
[/LIST]