Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8398201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:59:07+00:00 2026-06-09T20:59:07+00:00

I am not an expert in AppleScript, so I’ve ben trying to find an

  • 0

I am not an expert in AppleScript, so I’ve ben trying to find an example of AppleScript code that can successfully process a batch of Excel files (each one with a single worksheet), copying the content of each one into a single destination sheet.

This is the pseudo code that I had in mind:

pick source folder with Excel files;
pick destination Excel file;

for each file within the source folder:
        copy data from default sheet;
        paste data into destination sheet's first unused row
end

This is the code I came up with. It does open correctly each file, but the copy/past operation is just not happening. Any idea how to get it to work?


set main_folder to choose folder with prompt "Please select the folder containing the Excel files:"

set target_excel to choose file with prompt "Please select target Excel file:"

set excel_extension_list to {"xls", "xlsx", "csv"}

tell application "Finder"
    set excel_files to (files of main_folder whose name extension is in excel_extension_list) as alias list
end tell

tell application "Microsoft Excel"
    open target_excel

    repeat with a_file in excel_files
        open a_file
        activate a_file
        tell sheet 1 of workbook a_file
            set the_range to value of used range
            set number_of_source_rows to count of rows of the_range
        end tell

        activate target_excel
        tell sheet 1 of workbook target_excel
            set new_range to value of used range
            set number_of_destination_rows to count of rows of new_range
            set destination_range to range "A" & (number_of_destination_rows + 1) & ":E" & (number_of_destination_rows + 1 + number_of_source_rows)
            set value of destination_range to the_range
            close workbook a_file saving no
        end tell
    end repeat
end tell
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:59:09+00:00Added an answer on June 9, 2026 at 8:59 pm

    Tried and Tested in Excel 2011

    My Assumptions

    1. The destination file has a sheet called Sheet1
    2. I am retrieving info from the 1st sheet of all files. Change as applicable.

    CODE

    I have commented the code so you should not have any problem understanding it. 🙂

    Sub Sample()
        Dim wbI As Workbook, wbO As Workbook
        Dim lRowO As Long
        Dim lRowI As Long, lColI As Long
        Dim DestFile As Variant
        Dim RootFldr As String, FilesFolder As String, strFile As String
    
        '~~> Get the Root Folder
        RootFldr = MacScript("return (path to desktop folder) as String")
    
        '~~> Show the Folder Browser to select the folder which has the files
        FilesFolder = MacScript("(choose folder with prompt ""Please select the folder which has excel files""" & _
        "default location alias """ & RootFldr & """) as string")
    
        '~~> If user doesn't select anything then exit
        If FilesFolder = "" Then Exit Sub
    
        '~~> Show the File Select dialog for the output file
        DestFile = Application.GetOpenFilename("XLS8,XLS4")
    
        '~~> Open output file
        Set wbO = Workbooks.Open(DestFile)
    
        '~~> Get the next available row for writing
        lRowO = wbO.Sheets("Sheet1").Cells.Find(What:="*", _
                After:=wbO.Sheets("Sheet1").Range("A1"), _
                Lookat:=xlPart, _
                LookIn:=xlFormulas).Row + 1
    
        '~~> Loop through each file in the folder
        strFile = Dir(FilesFolder)
    
        Do While Len(strFile) > 0
            '~~> Check for the file if it is csv,xls or xlsx
            If Right(strFile, 3) = "csv" Or _
            Right(strFile, 3) = "xls" Or _
            Right(strFile, 4) = "xlsx" Then
                '~~> Open the file from the folder
                Set wbI = Workbooks.Open(FilesFolder & strFile)
    
                With wbI
                    '~~> Get the last row in the file from sheet #1
                    lRowI = .Sheets(1).Cells.Find(What:="*", _
                            After:=.Sheets(1).Range("A1"), _
                            Lookat:=xlPart, _
                            LookIn:=xlFormulas, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=False).Row
    
                    '~~> Get the last column in the file from sheet #1
                    lColI = .Sheets(1).Cells.Find(What:="*", _
                            After:=.Sheets(1).Range("A1"), _
                            Lookat:=xlPart, _
                            LookIn:=xlFormulas, _
                            SearchOrder:=xlByColumns, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=False).Column
    
                    With .Sheets(1)
                        '~~> Copy the selected range
                        .Range(.Cells(1, 1), .Cells(lRowI, lColI)).Copy
    
                        '~~> Paste in destination file
                        wbO.Sheets("Sheet1").Range("A" & lRowO).PasteSpecial xlValues
    
                        '~~> Get the next available row for writing
                        lRowO = wbO.Sheets("Sheet1").Cells.Find(What:="*", _
                                After:=wbO.Sheets("Sheet1").Range("A1"), _
                                Lookat:=xlPart, _
                                LookIn:=xlFormulas, _
                                SearchOrder:=xlByRows, _
                                SearchDirection:=xlPrevious, _
                                MatchCase:=False).Row + 1
                    End With
                End With
                '~~> Close the file after copying from it
                wbI.Close SaveChanges:=False
            End If
            strFile = Dir
        Loop
    
        MsgBox "Done"
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not that expert in SSIS. Can anybody help me out on my
I'm not an expert in programming in general. I can find my way around
I'm not very expert on how processors work, but one might imagine that it
I am not an expert at jquery but trying to get a menu to
Obviously, I'm not an expert in C#. I would like to simplify this code
I am not an expert but I am trying to write .NET regex expression
I am not an expert in Java; I am hoping that someone on this
To anyone who can help. I am not an expert at T-SQL so I
To anyone who can help. I am not an expert at T-SQL so I
I am not an expert in PHP. I am trying to increase the use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.