Hello there everyone. I am finishing up a prog that tracks student data, and now that I can put their data into a listview, I am hoping to be able to put it into an excel spreadsheet so teachers can save it for later reference.
I am using this code to basically open excel, and copy the listview data over, but the thing is, while I can adjust the column width of the listview columns no problem, is there a similar way to do it for excel once the spreadsheet is open? Or just make them just as wide as the ones in the listview? I am using this code to open excel, which works great!
But the only small issue is the columns sometimes look crowded unless I manually resize them, which is no big problem, but it would be more convenient for other teachers if it could do it when it opens. Has anyone any experience adjusting excel columns? Thanks!
I am using this code to basically open excel, and copy the listview data over, but the thing is, while I can adjust the column width of the listview columns no problem, is there a similar way to do it for excel once the spreadsheet is open? Or just make them just as wide as the ones in the listview? I am using this code to open excel, which works great!
VB Code:
Private Sub SaveToExcelONEDAY_Click() Dim ExcelObj As Object Dim ExcelBook As Object Dim ExcelSheet As Object Dim i As Integer Set ExcelObj = CreateObject("Excel.Application") Set ExcelBook = ExcelObj.WorkBooks.Add Set ExcelSheet = ExcelBook.WorkSheets(1) With ExcelSheet For i = 1 To ResultsView.ColumnHeaders.Count .cells(1, i) = ResultsView.ColumnHeaders(i).Text Next i For i = 1 To ResultsView.ListItems.Count .cells(i + 1, 1) = ResultsView.ListItems(i).Text .cells(i + 1, 2) = ResultsView.ListItems(i).SubItems(1) .cells(i + 1, 3) = ResultsView.ListItems(i).SubItems(2) .cells(i + 1, 4) = ResultsView.ListItems(i).SubItems(3) .cells(i + 1, 5) = ResultsView.ListItems(i).SubItems(4) .cells(i + 1, 6) = ResultsView.ListItems(i).SubItems(5) .cells(i + 1, 7) = ResultsView.ListItems(i).SubItems(6) Next End With ExcelObj.Visible = True End Sub
But the only small issue is the columns sometimes look crowded unless I manually resize them, which is no big problem, but it would be more convenient for other teachers if it could do it when it opens. Has anyone any experience adjusting excel columns? Thanks!