+ Reply to Thread
Results 1 to 8 of 8

Paste the contents of several folders into a spreadsheet

  1. #1
    Registered User
    Join Date
    08-12-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Smile Paste the contents of several folders into a spreadsheet

    Using a macro, I'm wanting to take a folder that has several sub-folders and have the sub-folder names go in the top row of each column in a spreadsheet and the files within each folder entered below each corresponding folder, preferably while being able to specify file types. I found a macro for pasting the contents of one folder at a time, but it doesn't enter the folder name, it doesn't loop and it places the file name starting on the active cell. I just want A1 to have the name of subfolder 1, B1 to have subfolder 2, and so on. It would also be nice if it added a new sheet each time the macro was ran. Can anyone help me with this?

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Paste the contents of several folders into a spreadsheet

    Paste the CONTENTS of those folders into individual columns, or paste a LISTING of the filenames in said folders?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    08-12-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Paste the contents of several folders into a spreadsheet

    It would be a listing of the filenames. For example, I would want it to list all the tif filenames in every subfolder in each column under the subfolder's name.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Paste the contents of several folders into a spreadsheet

    These three macros work together to accomplish this task. Drop them all into a new Module, edit the initialfilename in the StartingMacro so that it opens to a folder closer to where you expect to start. Then run that macro, it will use the other two macros to loop through every folder in the selected folder and run the HyperlinkFiles macro on each folder separately.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-12-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Paste the contents of several folders into a spreadsheet

    Thanks for the code. I gave it a try and I keep getting a "variable not defined" compile error for the LoopController sub routine for some reason. I am not experienced enough to figure it out unfortunately. From what I can tell the macro appears to be just what I was looking for with lots of flexibility. Any ideas on what could be causing the error?

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Paste the contents of several folders into a spreadsheet

    Only way I can review what you've done in your workbook is to see the workbook.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic


    Make sure all that code above goes into a single Module (Insert > Module)

  7. #7
    Registered User
    Join Date
    08-12-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Paste the contents of several folders into a spreadsheet

    I just opened a blank spreadsheet and VB, then pasted the code into a newly inserted Module and ran it. Is there supposed to be something in the spreadsheet prior to running the macro?

  8. #8
    Registered User
    Join Date
    08-12-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Paste the contents of several folders into a spreadsheet

    I don't know what is different, but I tried running it and it worked without getting any compiling errors. Thanks for the code!

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Paste the contents of several folders into a spreadsheet

    You're very welcome.

+ 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. [SOLVED] Paste into new workbook and save as depending on folders contents
    By ScabbyDog in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2013, 04:48 PM
  2. [SOLVED] Copy/Paste & Clear Contents Macro on multiple spreadsheet
    By greggatz in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-01-2012, 10:16 AM
  3. Macro to list folders and contents within it Including subfolders.
    By pekunda in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2012, 08:17 AM
  4. extracting file contents from different folders!
    By via135 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-11-2008, 02:21 PM
  5. [SOLVED] paste contents from other spreadsheet
    By JohnT in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-08-2005, 12:06 PM

Tags for this Thread

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