[RESOLVED] generating automatic col width in excel sheet using vb
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [RESOLVED] generating automatic col width in excel sheet using vb

  1. #1
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    464

    [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.

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: generating automatic col width in excel sheet using vb

    What is y?
    Code:
    osheet.Cells(r, c).ColumnWidth = y
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    464

    Question 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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center