-
Excel to Excel
anyone know how I can copy data from one excel document and then paste it into another by using VB?
this is a way to copy it, posted by Peet a while earlier
Code:
Option Explicit
Private Sub Command1_Click()
Dim sFile As String
Dim rs As ADODB.Recordset
Dim sconn As String
Dim i As Integer
On Error GoTo xit
sFile = "C:\TEST.XLS"
Set rs = New ADODB.Recordset
sconn = "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ=" & sFile
rs.Open "SELECT * FROM [Sheet1$]", sconn
While Not rs.EOF
For i = 0 To rs.Fields.Count - 1
Debug.Print rs.Fields(i).Name & " : " & rs.Fields(i).Value
Next i
rs.MoveNext
Wend
Set rs = Nothing
Exit Sub
xit:
MsgBox Err.Number & " -> " & Err.Description
End Sub
can I somehow now do the opposit of that and throw what is in the recordsets out into excel?