How to change column size in VB6 and Excel 2002
i tested below in VB6.0 and Excel2003. it could change the column width of a
column, and almost your code also could change the width of column.
Sub testVB6()
Dim oApp As Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Set oApp = New Excel.Application
oApp.Visible = True
On Error Resume Next
Set oBook = oApp.Workbooks.Open("C:\testsample.xls")
If oBook Is Nothing Then
Set oBook = oApp.Workbooks.Add
oBook.SaveAs "C:\testsample.xls"
End If
Set oSheet = oBook.Worksheets(1)
oSheet.Columns("A").ColumnWidth = 5.75
oSheet.Range("A1") = oSheet.Columns("A").ColumnWidth
oApp.DisplayAlerts = False
oBook.Close SaveChanges:=True
Set oSheet = Nothing
Set oBook = Nothing
oApp.Quit
Set oApp = Nothing
End Sub
keiji
"Tony Girgenti" wrote in message
...
Hello.
Using VB6.0 and Excel 2002. I'm trying to change the column width of a
column before saving the workbook. I can do other changes to the
worksheet,
like fonts and values etc., but it won't change the columnwidth.
I tried these statements and none of them work:
oSheet.Range("A1").Columns.ColumnWidth = 5.75
oSheet.Range("A1").ColumnWidth = 5.75
oSheet.Columns("A:A").ColumnWidth = 5.75
oSheet.Columns("A").Select
Selection.ColumnWidth = 5.75
Does anybody know how to do this?
Any help would be gratefully appreciated.
Thanks,
Tony
|