|
-
Jun 17th, 2004, 02:52 AM
#1
Thread Starter
Lively Member
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...
-
Jun 17th, 2004, 03:02 AM
#2
I found this code and have used it in one of my apps. HTH 
VB Code:
Public Sub CopyTableData()
fldCount = rsSelectedTrades.Fields.Count
recArray = rsSelectedTrades.GetRows
recCount = UBound(recArray, 2) + 1
objExcel.Cells(34, 80).Resize(recCount, fldCount).Value = TransposeDim(recArray)
End Sub
Function TransposeDim(v As Variant) As Variant
' Custom Function to Transpose a 0-based array (v)
Dim X As Long, Y As Long, Xupper As Long, Yupper As Long
Dim tempArray As Variant
Xupper = UBound(v, 2)
Yupper = UBound(v, 1)
ReDim tempArray(Xupper, Yupper)
For X = 0 To Xupper
For Y = 0 To Yupper
tempArray(X, Y) = v(Y, X)
Next Y
Next X
TransposeDim = tempArray
End Function
-
Jun 17th, 2004, 03:15 AM
#3
Fanatic Member
I myself have been creating a report generator exporting info from SQl Server stored procs to Excel.
VB Code:
'populate a recordset recExport with the info from Access
'Set up column headers
Dim objFiled As Field
For Each objFiled In recExport.Fields
With m_objSheet.Cells(1, intFieldCounter)
.Value = Replace$(objFiled.Name, "_", Space(1))
.Font.Bold = True
.Font.Size = 11
.Interior.Color = &H808080
End With 'objSheet.Cells(1, intFieldCounter)
intFieldCounter = intFieldCounter + 1
Next 'objFiled
'Export the recordset to the worksheet
m_objSheet.Range("a2").CopyFromRecordset recExport
m_objSheet.Columns.AutoFit
m_objSheet.Activate
m_objSheet.Rows(2).Select
m_objApp.ActiveWindow.FreezePanes = True
sorry in a rush but I hope this helps.
Useful Links
.Net
#Develop, GhostDoc, CodeKeep , be.PINVOKE, Good Code Snippet Site
Krypton Toolkit, XPCC / XP Common Controls, QSS Windows Forms Components
VB.COM
VB.Classic Help File, MB Controls, MZTools, ADO Stored Procedure Generator add-in,
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
|