+ Reply to Thread
Results 1 to 9 of 9

Macro to open folder on desktop and certain files within

  1. #1
    Registered User
    Join Date
    07-28-2014
    Location
    Richmond, VA
    MS-Off Ver
    excel 2010
    Posts
    12

    Macro to open folder on desktop and certain files within

    I am trying to create a very large macro that covers alot of ground for a data analysis project. The first sub macro that I need to create is the following:

    In a newly opened workbook, I want to run a macro that will open a folder on the desktop (of anyone's PC) called "Input". Inside "Inupt" will be a number of subfolders; I will call them "sub_1" "sub_2" "sub_3" ...... "sub_n" The number of subfolders, n, is undefined and will change each time I run the macro (conditional). Inside each subfolder will be a .csv file. I would like this macro to open each of the .csv files located within the subfolders within the main folder "Input". After all of the .csv files are open, I would like the macro to copy everything in each .csv file and paste into a different sheet in the originally opened excel workbook.

    Any help would be greatly appreciated as I am very new to VBA based macro building.

    Thanks!

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Macro to open folder on desktop and certain files within

    So to clarify you want the following to be automated.

    Open each CSV in a folder and all subfolders
    Copy EACH into a new tab into what file?
    Can it be the one with the macro or another one?

    Why not copy each dataset into ONE data tab? What are you trying to accomplish with all of these tabs?

    Depending on what you are trying to do, I would copy each of the CSV datasets to ONE data tab and add a column to indicate what workbook it came from. Then you can use that pretty/tidy data to have pivot tables or any reporting off of.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,860

    Re: Macro to open folder on desktop and certain files within

    Here is a tutorial that will get you close. You will need to modify the code slightly, but it will teach you how to get what you are looking to do. Post back with specific questions.

    https://www.youtube.com/watch?v=MFOc...s_digest-vrecs
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    07-28-2014
    Location
    Richmond, VA
    MS-Off Ver
    excel 2010
    Posts
    12

    Re: Macro to open folder on desktop and certain files within

    mikeTRON:

    Yes, there will be an undefined number of .CSV files, each individually in a subfolder, and all subfolders within the main folder: "Input"
    Copy EACH into a new tab on a fresh/new workbook (the one I open to run the macro...).

    I can't do one tab because the data has thousands and thousands of pieces of information per file- all in the same format. And I am looking for a certain thing from each one after I adjust it with another sub macro... however i've already done that one. The end game is to summarize all of the tabs in one summary tab so that I can export to Access. This tool is being developed to simplify our method of analyzing data for a complex process.

  5. #5
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Macro to open folder on desktop and certain files within

    is there only ONE tab in the CSV?

    If so you can use a batch file to combine them all (to be more than one MILLION rows) then import that into access or powerpivot and you are done, NO vba necessary.

    I have done this exact thing on over 4M records. the batch to combine the CSV is absurdly simple (using dos commands) then you just import the CSV.

    PowerPivot is free and EPIC.

  6. #6
    Registered User
    Join Date
    07-28-2014
    Location
    Richmond, VA
    MS-Off Ver
    excel 2010
    Posts
    12

    Re: Macro to open folder on desktop and certain files within

    Please Login or Register  to view this content.
    Last edited by alansidman; 07-29-2014 at 06:12 PM. Reason: code tags added

  7. #7
    Registered User
    Join Date
    07-28-2014
    Location
    Richmond, VA
    MS-Off Ver
    excel 2010
    Posts
    12

    Re: Macro to open folder on desktop and certain files within

    sorry for the long post. This is what I came up with to do what I need done. However, it won't actually paste into the new sheet in my original workbook. It opens the CSV file, selects the data, and copies the data, but doesnt paste.

    Any thoughts?

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,860

    Re: Macro to open folder on desktop and certain files within

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)

  9. #9
    Registered User
    Join Date
    07-28-2014
    Location
    Richmond, VA
    MS-Off Ver
    excel 2010
    Posts
    12

    Re: Macro to open folder on desktop and certain files within

    Thanks alansidman, I apologize!

    And I figured this one out! thanks

+ 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] VBA to rename PDF files saved in Desktop folder using excel 2010
    By Chandrahaas in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 09-08-2022, 09:27 AM
  2. Macro to Open specific files in a Folder
    By lorena.tgarza in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-15-2012, 09:01 AM
  3. Macro to open up all files in certain folder
    By dpcp in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-06-2012, 03:26 PM
  4. Open file in folder on Desktop
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 09-17-2010, 10:35 AM
  5. [SOLVED] Excel macro to open files within a folder
    By Craig in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-08-2005, 04:05 AM

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