+ Reply to Thread
Results 1 to 8 of 8

VBA code combine multiple workbooks into one with filename included from selected folder

  1. #1
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    VBA code combine multiple workbooks into one with filename included from selected folder

    Hi,

    I would like to seek help in creating a macro to combine multiple workbooks into one (append) and add a column to include their filenames. The macro should first ask to browse the folder where the excel files are located.

    Thank you in advance!

    Ron

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: VBA code combine multiple workbooks into one with filename included from selected fold

    to browse the folder where the files are located, you are going to want to use the FILE DIALOG object in VBA. you can find the documentation on it here: file dialog method in VBA. regarding your question about combining multiple workbooks into one, you have not given any detailed information about what you want to do. there are multiple sheets in each workbook and the only thing you said was that you wanted to append them. so, what exactly does that mean?

  3. #3
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code combine multiple workbooks into one with filename included from selected fold

    There is only 1 sheet in each workbook all with the same columns and I need to append all of them in one workbook.

  4. #4
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: VBA code combine multiple workbooks into one with filename included from selected fold

    have you ever used code before in excel? someone might give you the code, but if you want a wonderful start, take a look at the following links for objects you could make very good use of. this is the official documentation from microsoft, just like all other languages have official documentation for their own communities:

    fileDialog object

    workbook object

    capturing a file name of an excel file selected with the ''fileDialog'' object

    excel's range object

  5. #5
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code combine multiple workbooks into one with filename included from selected fold

    Thank you. I am a novice at creating VBA codes. I did this in power query unfortunately data in one of the columns is being truncated that is why I am looking for a vba code to do this instead.

  6. #6
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: VBA code combine multiple workbooks into one with filename included from selected fold

    if I'm not mistaken power query can only pull data from one dataset at a time regardless if it's an internal or external source correct?

    I'm currently on a phone posting this but maybe I can put together some code that can do something like what you want later on but hopefully someone else is not busy and maybe can give you a start here. I try not to write all the coat someone needs a rather just a replica so they can learn it so they don't have to ask the same question a second time.

  7. #7
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code combine multiple workbooks into one with filename included from selected fold

    Power query can pull from different workbooks and sheets both internal and external. I just cannot seem to find out why it truncates data when it is way below the limit of 32k characters. Max character I have in a cell is 1k+. I am pressed for time now so I would appreciate if I can get a complete code. I found one but it only copies the sheets from different workbooks and creates a new tabs in the master file where it should be collated. It does not append it like how I need it.

  8. #8
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: VBA code combine multiple workbooks into one with filename included from selected fold

    well, that seems strange, as according to this article, the max cell length is a simple power of 2, which of course it should be:

    https://communities.sas.com/t5/SAS-P...et/td-p/199915

    how pressed for time are you? generally, I don't think that makes folks happy because they help for free. however, can you adopt the following code and finish it by figuring out how to copy your column data and file names? I am opening all of the workbooks for you and cycling through all the sheets in each workbook. you can figure out the rest with the macro recorder:
    Please Login or Register  to view this content.
    please note that my code does not take into account the index lower and upper bounds. so, if it errors out, just change those bounds of the counter variables. you can take it from here.

+ 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. Help make my code work: Loop through folder of workbooks with multiple sheets and combine
    By carlito2002wgn in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-06-2019, 08:19 PM
  2. Replies: 3
    Last Post: 02-06-2018, 12:53 PM
  3. Replies: 9
    Last Post: 08-04-2016, 06:40 AM
  4. Combine same sheet from multiple workbooks in the same folder
    By a1b2c3d4e5f6g7 in forum Excel General
    Replies: 2
    Last Post: 05-29-2015, 03:20 PM
  5. [SOLVED] combine 1st sheet from all workbooks in folder
    By onbeillp111 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-18-2014, 05:14 PM
  6. Combine workbooks into an existing workbook in the same folder
    By uberathlete in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2014, 01:51 PM
  7. Need Code to Combine All Workbooks in Folder
    By jcranst in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-01-2012, 02:18 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