Results 1 to 3 of 3

Thread: How to Export to Excel Sheet

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    chennai, Tamil Nadu, India.
    Posts
    84

    How to Export to Excel Sheet


    I want to export MS Access 2000 records to Excel sheet from vb6.0? How to do it?

    thanx in advance...
    S.Desikan

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    I found this code and have used it in one of my apps. HTH

    VB Code:
    1. Public Sub CopyTableData()
    2.  
    3. fldCount = rsSelectedTrades.Fields.Count
    4.        
    5. recArray = rsSelectedTrades.GetRows
    6.  
    7. recCount = UBound(recArray, 2) + 1
    8.        
    9. objExcel.Cells(34, 80).Resize(recCount, fldCount).Value = TransposeDim(recArray)
    10.  
    11. End Sub
    12.  
    13. Function TransposeDim(v As Variant) As Variant
    14. ' Custom Function to Transpose a 0-based array (v)
    15.    
    16.     Dim X As Long, Y As Long, Xupper As Long, Yupper As Long
    17.     Dim tempArray As Variant
    18.    
    19.     Xupper = UBound(v, 2)
    20.     Yupper = UBound(v, 1)
    21.    
    22.     ReDim tempArray(Xupper, Yupper)
    23.     For X = 0 To Xupper
    24.         For Y = 0 To Yupper
    25.             tempArray(X, Y) = v(Y, X)
    26.         Next Y
    27.     Next X
    28.    
    29.     TransposeDim = tempArray
    30.  
    31. End Function

  3. #3
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667
    I myself have been creating a report generator exporting info from SQl Server stored procs to Excel.

    VB Code:
    1. 'populate a recordset recExport with the info from Access
    2.  
    3.             'Set up column headers
    4.             Dim objFiled As Field
    5.             For Each objFiled In recExport.Fields
    6.  
    7.                 With m_objSheet.Cells(1, intFieldCounter)
    8.                     .Value = Replace$(objFiled.Name, "_", Space(1))
    9.                     .Font.Bold = True
    10.                     .Font.Size = 11
    11.                     .Interior.Color = &H808080
    12.                 End With 'objSheet.Cells(1, intFieldCounter)
    13.  
    14.                 intFieldCounter = intFieldCounter + 1
    15.             Next 'objFiled
    16.  
    17.        
    18.             'Export the recordset to the worksheet
    19.             m_objSheet.Range("a2").CopyFromRecordset recExport
    20.  
    21.             m_objSheet.Columns.AutoFit
    22.             m_objSheet.Activate
    23.             m_objSheet.Rows(2).Select
    24.             m_objApp.ActiveWindow.FreezePanes = True

    sorry in a rush but I hope this helps.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width