+ Reply to Thread
Results 1 to 2 of 2

Quick Way to Append an Excel File as a Sheet onto Another File

Hybrid View

  1. #1
    Registered User
    Join Date
    04-08-2022
    Location
    Atlanta
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    1

    Quick Way to Append an Excel File as a Sheet onto Another File

    I have about 90 different excel files, each of which is a report for a different customer. I also have a generic summary tab that I need to add into every one of those 90 reports. Is there a way to automate this process?

    Basically, I have 91 files - 90 of which are unique reports and 1 file, which is the generic summary tab. Need a quick way to slot in that generic summary file as a sheet in all the reports.

    Thanks in advance!

  2. #2
    Valued Forum Contributor
    Join Date
    03-24-2020
    Location
    Thailand
    MS-Off Ver
    Office 2024
    Posts
    982

    Re: Quick Way to Append an Excel File as a Sheet onto Another File

    Hi ankini,

    This can be done with a VBA macro.
    Copy the code below into a module in the SOURCE workbook, the one with the summary sheet you want to copy across.

    In the code, there are a couple of bits which you need to update before running:
    • The name of the sheet you want to copy. Replace "Sheet1" with whatever your sheet is called.
      The location (folder) where your 90 files are. Ensure the file path is in double quotation marks and has a final back-slash before the closing double quotations.
    The code will run through all files and insert the source sheet in all .xlsx files in the specified folder.


    Option Explicit
    
    Sub copyWorksheetToAll()
    
    Application.ScreenUpdating = False
    
    ' Set SOURCE workbook/worksheet
        Dim sourceWB As Workbook
        Dim sourceWS As Worksheet
    
        Set sourceWB = ThisWorkbook
        Set sourceWS = sourceWB.Sheets("Sheet1")   ' <<< Update sheetname !!!
    
    ' Creates collection of filenames to be appended
        Dim loopFolder As String
        Dim fName As Variant
        Dim myFiles As New Collection
    
    ' Enter folder name where files are to be appended
    ' ### Ensure backslash before end double-quote  !!!  ###
        loopFolder = "C:\Users\Sample\Desktop\CopyTest\"
        fName = Dir(loopFolder & "*.xlsx")
    
        Do While fName <> ""
            myFiles.Add fName
            fName = Dir
        Loop
    
    ' Loops through all files & add copy of sheet
        Dim wb As Workbook
    
        For Each fName In myFiles
            Set wb = Workbooks.Open(Filename:=(loopFolder & fName))
            sourceWS.Copy after:=wb.Sheets(1)
            wb.Save
            wb.Close
        Next
    
    Application.ScreenUpdating = True
    
    MsgBox "Sheet had been copied into all .xlsx files in the folder.", vbInformation, "Task completed"
    
    End Sub

    PS: For testing, use copies of your files or ensure you have them backed up.
    If your Question is answered; please mark it SOLVED. If you are happy with a member's solution, say 'Thanks' and click the 'Star' to Add Reputation.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro To append Data from a monthly file to Master file Based on Column Headers
    By ashwankumar in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-05-2016, 11:15 PM
  2. Replies: 0
    Last Post: 01-20-2015, 10:07 PM
  3. [SOLVED] Saving MASTER file, automatically remove part of file name and append current date?
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-10-2014, 08:13 AM
  4. Copy cell value of all file in the folder and append to Master file
    By snsuvarna in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-04-2013, 11:55 AM
  5. Append data from multiple sheets into 1 new sheet in a new file
    By samkap in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-28-2012, 02:20 AM
  6. Replies: 0
    Last Post: 11-16-2011, 01:35 PM
  7. Append the data given in diff sheets of an Excel File to one sheet
    By sansk_23 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-09-2005, 09:06 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