Results 1 to 14 of 14

Write data to a closed workbook

Threaded View

  1. #1
    Forum Contributor Dave H9's Avatar
    Join Date
    03-10-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    418

    Write data to a closed workbook

    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
    Last edited by Dave H9; 06-16-2011 at 02:59 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1