Public Sub Button4_click(ByVal sender As Object, e As System.EventArgs) Handles Button4.Click
ListBox1.Sorted = True
EXCLSetup(ListBox1)
End Sub
Public Sub EXCLSetup(ByVal listbox_var As ListBox)
Dim objExcel As New Excel.Application
objExcel.Visible = True
objExcel.Workbooks.Add()
For idx As Integer = 0 To listbox_var.Items.Count - 1
Dim cell As String = String.Format("A{0}", 2 + idx)
objExcel.Range(cell).Select()
objExcel.ActiveCell.Value = listbox_var.Items(idx)
Next
objExcel = Nothing
End Sub
[\code]
However, I would like to export it to the same file that I imported early (code for importing:
[code]
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
ListBox1.Items.Clear()
With OpenFileDialog1
.ShowReadOnly = False
.Filter = "All Files|*.*|Excel Files (*)|*;*.xls;*.xlsx"
.FilterIndex = 2
If .ShowDialog = DialogResult.OK Then
APP1 = New Excel.Application
workbook1 = APP1.Workbooks.Open(.FileName)
worksheet1 = workbook1.Worksheets("sheet1")
End If
End With
Dim objRange As Excel.Range
For intLoopCounter = 1 To CInt(worksheet1.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row)
objRange = worksheet1.Range("A" & intLoopCounter)
ListBox1.Items.Add(objRange.Value)
Next intLoopCounter
'rest just organizes the data and not important here
ListBox3.Items.Clear()
ListBox3.Items.AddRange(ListBox1.Items.Cast(Of String).Except(ListBox2.Items.Cast(Of String)).ToArray)
End Sub
I've tried
objExcel.Workbooks.Add(.FileName)
and other assorted things but this one is stumping me, thoughts/comments?
Public Sub Button4_click(ByVal sender As Object, e As System.EventArgs) Handles Button4.Click
ListBox1.Sorted = True
EXCLSetup(ListBox1)
End Sub
Public Sub EXCLSetup(ByVal listbox_var As ListBox)
Dim objExcel As New Excel.Application
objExcel.Visible = True
objExcel.Workbooks.Add()
For idx As Integer = 0 To listbox_var.Items.Count - 1
Dim cell As String = String.Format("A{0}", 2 + idx)
objExcel.Range(cell).Select()
objExcel.ActiveCell.Value = listbox_var.Items(idx)
Next
objExcel = Nothing
End Sub
[\code]
However, I would like to export it to the same file that I imported early (code for importing:
[code]
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
ListBox1.Items.Clear()
With OpenFileDialog1
.ShowReadOnly = False
.Filter = "All Files|*.*|Excel Files (*)|*;*.xls;*.xlsx"
.FilterIndex = 2
If .ShowDialog = DialogResult.OK Then
APP1 = New Excel.Application
workbook1 = APP1.Workbooks.Open(.FileName)
worksheet1 = workbook1.Worksheets("sheet1")
End If
End With
Dim objRange As Excel.Range
For intLoopCounter = 1 To CInt(worksheet1.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row)
objRange = worksheet1.Range("A" & intLoopCounter)
ListBox1.Items.Add(objRange.Value)
Next intLoopCounter
'rest just organizes the data and not important here
ListBox3.Items.Clear()
ListBox3.Items.AddRange(ListBox1.Items.Cast(Of String).Except(ListBox2.Items.Cast(Of String)).ToArray)
End Sub
Edit: fixed a wrong slash

New Topic/Question
Reply



MultiQuote



|