Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21740

Adjusting the column width of an excel spreadsheet?

$
0
0
Hello there, I am working on a math program that will record student answers and export them to an excel spreadsheet from a listview called ResultsView.

I can export the data to the right columns, but once the data is exported, I would like to be able to change the width of the columns of the spreadsheet, sort of like you can do in a listview.

I export the data this way, and it will do the job well, but is there an option to change the width of the columns?

VB Code:
  1. Dim ExcelObj As Object
  2.     Dim ExcelBook As Object
  3.     Dim ExcelSheet As Object
  4.     Dim i As Integer
  5.  
  6.     Set ExcelObj = CreateObject("Excel.Application")
  7.     Set ExcelBook = ExcelObj.WorkBooks.Add
  8.     Set ExcelSheet = ExcelBook.WorkSheets(1)
  9.    
  10.  
  11.      
  12.      
  13.  
  14.     With ExcelSheet
  15.         'For i = 1 To ResultsView.ColumnHeaders.Count
  16.            ' .cells(1, i) = ResultsView.ColumnHeaders(i).Text
  17.        ' Next i
  18.        
  19.        ' This code below will print the resultsview listview columns into the excel spreadsheet
  20.         For i = 1 To ResultsView.ListItems.Count
  21.             .cells(i + 1, 1) = ResultsView.ListItems(i).Text
  22.             .cells(i + 1, 2) = ResultsView.ListItems(i).SubItems(1)
  23.             .cells(i + 1, 3) = ResultsView.ListItems(i).SubItems(2)
  24.             .cells(i + 1, 4) = ResultsView.ListItems(i).SubItems(3)
  25.            
  26.             .cells(i + 1, 5) = ResultsView.ListItems(i).SubItems(4)
  27.             .cells(i + 1, 6) = ResultsView.ListItems(i).SubItems(5)
  28.             .cells(i + 1, 7) = ResultsView.ListItems(i).SubItems(6)
  29.  
  30.  
  31.         Next
  32.     End With
  33.    
  34.     ExcelObj.Visible = True
Thank you!!!

Viewing all articles
Browse latest Browse all 21740

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>