I am attempting to copy all the data from a listbox into excel (ideally I would just like to copy it to the clipboard but unsure how)
Anyway, below is my code that's throws our this error:
User-defined type not defined
Code Below:
Dim oExcel As Excel.Application ' Excel Application
Set oExcel = New Excel.Application ' Start it
oExcel.Workbooks.Open "J:\Book2.xlsx" ' **** CHANGE NAME HERE **** Open it.
On Error GoTo kill_task
Col = Listbox31.ColumnCount ' Number of Columns
Row = Listbox31.ListCount ' Number of Rows
For c = 1 To UBound(Col) ' For each Column
For L = 1 To UBound(Row) ' in Each Line
oExcel.Cells(j, i) = Listbox31.List(j - 1, i - 1) ' Write the value for Line, Columns
Next L ' Next Line
Next c ' Next Col
oExcel.ActiveWorkbook.Save ' Save
oExcel.Workbooks(1).Close ' Close Workbook
oExcel.Application.Quit ' Close Application
Exit Function
kill_task:
oExcel.ActiveWorkbook.Save ' Save
oExcel.Workbooks(1).Close ' Close Workbook
oExcel.Application.Quit ' Close Application
End Function
c,L,j,i,Col,Roware all undeclared. My guess is you are usingjandibefore you declare them or set them to anything. Make sure you are usingOption Explicit, it saves time debugging.