I am attempting to speed up a project I am working on, the first step has been solved here, many thanks for the help. I now want to copy data to a closed workbook.
I have found the following code which proves it is possible -
Sub aaa()
Set cn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
cn.Open "provider=microsoft.jet.oledb.4.0;data source = C:\Documents and Settings\U116873\Desktop\a.xls; extended properties = ""excel 8.0; imex=1, hdr=yes"""
rs.Open "select * from [sheet1$]", cn, 3, 3 'adOpenStatic, adLockOptimistic
Range("B1").CopyFromRecordset rs
rs.MoveFirst
rs.Fields(0).Value = Range("A1").Value + Range("B1").Value
rs.Update
Set rs = Nothing
Set cn = Nothing
End Sub
Rylo posted it on this site here.
I can get this code to work however I am unsure how to incorporate into my existing code (also greatfully gathered with the help of this forum).
This is an example of the code I am using -
Sheet12.Range("J3:T3").Copy 'NEED ATTENTION 2
Workbooks.Open (strWorkbookPath & strWorkbookName)
Set LstNtr = Range("A3:A4000").End(xlDown).Offset(1, 0)
LstNtr.Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveWorkbook.Save
ActiveWorkbook.Close
So what I want to achieve is to replace the (very slow) process of copy, open, paste, save and close, as this occurs at numerous points in my complete progress.
Thanks in advance for your help
Dave H
Bookmarks