Results 1 to 3 of 3

Copying multiple files to 1 new workbook

Threaded View

  1. #1
    Registered User
    Join Date
    09-10-2008
    Location
    Derby
    Posts
    1

    Copying multiple files to 1 new workbook

    Hi
    I'm new to VBA macro scripting in Excel. However, I have the below code, which I need help with.

    The idea is it opens a number of files from my Y:/Scripts4/ folder names 1.xls, 2.xls, 3.xls, 4.xls etc and, for each one it opens, it copies cell range B10:O29 to a new file, I've just called "collate_new.xls"

    Everything works, except the line in bold, so I assume I have this wrong. Can anyone help?

    Thanks
    Tim

    p.s also, I want the data to be pasted into collate_new, and then the next set of data to be pasted after it etc, not overwritten. Not sure if the code below allows me to do that, but that's the aim.

    Sub collate_new()
    
    Dim sFile As String
    Dim arFiles(100) As String
    Dim i As Integer, j As Integer
    
    sFile = Dir$("Y:\Scripts4\*.xls", vbNormal)
        i = 0
        
    ' Fills array
        Do While sFile <> ""
          arFiles(i) = sFile
          sFile = Dir$()
           i = i + 1
        Loop
    ' Loop opens, copys and pastes
        For j = 0 To i - 1
            Workbooks.Open Filename:=arFiles(j)
            Closerfile = arFiles(j)
        Range("B10:O29").Copy
             Windows("Collate_new").Activate
        ActiveSheet.Paste
             Windows(arFiles(j)).Activate
            ActiveSheet.Close
      
             
        Next
    
    End Sub
    Last edited by royUK; 09-10-2008 at 08:07 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need Truth on Shared workbook & VB
    By dimitrz in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-29-2008, 01:42 AM
  2. Change a page number on a workbook with multiple sheets
    By sengelbrecht in forum Excel General
    Replies: 3
    Last Post: 08-21-2007, 04:01 PM
  3. Convert Multiple CSV Files to XLS Files Automatically
    By davehunter in forum Excel General
    Replies: 0
    Last Post: 07-11-2007, 05:42 AM
  4. Pivot table across multiple tabs in a workbook
    By mbrant in forum Excel General
    Replies: 4
    Last Post: 03-09-2007, 01:19 PM
  5. Copying Data from workbook a to workbook b, many times
    By jhumphrey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-01-2007, 12:41 PM

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