-
May 24th, 2011, 12:34 PM
#1
[RESOLVED] generating automatic col width in excel sheet using vb
i simple want sheet needs to be autoadjust in excel sheet.and the column does not go beyond the another sheet .can anybody tell me ?How should i do it ?tHX in advance.
Code:
i = 0
For Each adofields In rssales.Fields
osheet.Range("A1").Offset(0, i).Value = UCase(adofields.Name)
osheet.Range("A1:M1").Font.Bold = True
osheet.Cells(r, c).ColumnWidth = y
i = i + 1
Next
Last edited by firoz.raj; May 24th, 2011 at 12:37 PM.
-
May 24th, 2011, 02:12 PM
#2
Re: generating automatic col width in excel sheet using vb
What is y?
Code:
osheet.Cells(r, c).ColumnWidth = y
-
May 24th, 2011, 02:15 PM
#3
Re: generating automatic col width in excel sheet using vb
yea, it has resolved now autofitselection is working well .
Code:
Public Function CreateExcelSheet(ByRef rssales As ADODB.Recordset) As String
On Error GoTo errhnd
Dim FileNumber, i%
Dim filename$
i = 0
For Each adofields In rssales.Fields
osheet.Range("A1").Offset(0, i).Value = UCase(adofields.Name)
osheet.Range("A1:M1").Font.Bold = True
i = i + 1
Next
osheet.Range("A2").CopyFromRecordset rssales
osheet.Columns("H").Delete
osheet.Columns("A").Delete
osheet.Cells.Select
osheet.Cells.EntireColumn.AutoFit
objexcel.Application.DisplayAlerts = False
osheet.Range("A1").Select
filename = "C:\CNK\" & Format$(Date, "DDMMYYYY") & ".xls"
wbook.SaveAs path
wbook.Close
objexcel.Application.DisplayAlerts = False
objexcel.Quit
CreateExcelSheet = filename
Call SendMail(filename)
Exit Function
errhnd:
If Err.Number <> 0 Then
logfilename = "C:\CNK\" & Format$(Now, "DDMMYYYY") & ".txt"
FileNumber = FreeFile()
Open logfilename For Append As #FileNumber
Print #FileNumber, Err.Number, Err.Description, Now()
Close #FileNumber
End If
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|