S
Stevennguyen2206
Guest
I want to import from excel with combobox
It's error line 5: Dim RetailerWorksheet = RetailerWorkbook.Sheet1
My code :
Imports Microsoft.Office.Interop.Excel
Public Class Form1
Dim ExcelApp = New Microsoft.Office.Interop.Excel.Application
Dim RetailerWorkbook = ExcelApp.Workbooks.open("I:\Retailer.xlsx")
Dim RetailerWorksheet = RetailerWorkbook.Sheet1
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim iStaredRow As Integer
Dim iTotalrows As Integer
iTotalrows = ExcelApp.ActiveWorkbook.Sheet(1).Rang("a1").Currentregion.rows.count
For iStaredRow = 2 To iTotalrows
If Me.ComboBox1.Text = RetailerWorksheet.Cell(iStaredRow, 1).text Then
Me.ComboBox1.Text = RetailerWorksheet.Cells(iStaredRow, 2).text
End If
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim StartedRow As Integer
Dim TotalRows As Integer
Me.ComboBox1.Items.Clear()
TotalRows = ExcelApp.ActiveWorkbook.sheet(1).Range("a1").Curremtregion.Row.Count
For StartedRow = 2 To TotalRows
Me.ComboBox1.Items.Add(RetailerWorksheet.cell(StartedRow, 1).Text)
Next
MessageBox.Show(" Reatiler name has been successfully added into the combobox.", " combobox status")
End Sub
End Class
Tks all!
Continue reading...
It's error line 5: Dim RetailerWorksheet = RetailerWorkbook.Sheet1
My code :
Imports Microsoft.Office.Interop.Excel
Public Class Form1
Dim ExcelApp = New Microsoft.Office.Interop.Excel.Application
Dim RetailerWorkbook = ExcelApp.Workbooks.open("I:\Retailer.xlsx")
Dim RetailerWorksheet = RetailerWorkbook.Sheet1
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim iStaredRow As Integer
Dim iTotalrows As Integer
iTotalrows = ExcelApp.ActiveWorkbook.Sheet(1).Rang("a1").Currentregion.rows.count
For iStaredRow = 2 To iTotalrows
If Me.ComboBox1.Text = RetailerWorksheet.Cell(iStaredRow, 1).text Then
Me.ComboBox1.Text = RetailerWorksheet.Cells(iStaredRow, 2).text
End If
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim StartedRow As Integer
Dim TotalRows As Integer
Me.ComboBox1.Items.Clear()
TotalRows = ExcelApp.ActiveWorkbook.sheet(1).Range("a1").Curremtregion.Row.Count
For StartedRow = 2 To TotalRows
Me.ComboBox1.Items.Add(RetailerWorksheet.cell(StartedRow, 1).Text)
Next
MessageBox.Show(" Reatiler name has been successfully added into the combobox.", " combobox status")
End Sub
End Class
Tks all!
Continue reading...