9 replies
by kevin.riggs
The following code will work (at least it worked for me). You will have to have a reference to MS ActiveX Data Library (I used 2.5) and Microsoft Excel Object (I used 9.0 which is Office 2000).
------------CODE SNIPPET-------------
DimoXL As Excel.Application
Set oXL = New Excel.Application
Dim rs As New ADODB.Recordset
With rs
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.Fields.Append "Name", adVarChar, 100 .Fields.Append "Field2", adVarChar, 100
.Open
.AddNew
!Name = "Kevin"
!Field2 = "test"
.AddNew
!Name = "Cindee"
!Field2 = "test"
.UpdateBatch
End With
rs.MoveFirst
oXL.Visible = True
oXL.Workbooks.Add
Dim iLastWorksheet As Integer
Dim wsActive As Excel.Worksheet
iLastWorksheet = 3
WhileNot rs.EOF
oXL.Workbooks(1).Worksheets.Add After:=oXL.Workbooks(1).Worksheets(iLastWorksheet)
iLastWorksheet = iLastWorksheet + 1
Set wsActive = oXL.Workbooks(1).Worksheets(iLastWorksheet)
wsActive.Range("A1").Select
oXL.ActiveCell.Value = rs("Name")
wsActive.Range("B1").Select
oXL.ActiveCell.Value = rs("field2")
rs.MoveNext
Wend
oXL.DisplayAlerts = False
Dim iOldWorksheet As Integer
For iOldWorksheet = 1 To 3
oXL.Workbooks(1).Worksheets(1).Delete
Next
oXL.DisplayAlerts = True
Set oXL = Nothing
----------------End Snippet---------------
by jbeales
by kevin.riggs
by jbeales
by limbo
I'll send you I VB Project that demonstrates this with an access database.
All you should have to do is change the database environment settings, to match your own.
by jbeales
by limbo
I'll send you a VB Project that demonstrates this with an access database.
All you should have to do is change the database environment settings, to match your own.
by jbeales
by jbeales
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending