+ Reply to Thread
Results 1 to 7 of 7

Choose a Folder and loop a sub

  1. #1
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    110

    Choose a Folder and loop a sub

    Hi,

    I would like to ask for help for a code to:
    1. Choose a folder
    2. Loop a sub for all the files inside the chosen folder.

    all files in the folders are .xls

    Couldnt find anything online that allows me to paste my existing sub.

    Appreciate any help

  2. #2
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Choose a Folder and loop a sub

    Like this?

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    110

    Re: Choose a Folder and loop a sub

    I would need a code to allow me to choose a 1 folder and loop the files in that chosen folder only

  4. #4
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Choose a Folder and loop a sub

    That is what it does... however I have amended it slightly so that you only have to put the folder location in once.

    Please Login or Register  to view this content.
    The blue highlighted code opens each file in the folder and then closes and saves it at the completion of your code, but you can take them out if you need.

  5. #5
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    110

    Re: Choose a Folder and loop a sub

    Appreciate your help and I apologise if I was unclear.
    There are more than 1 folder location. I ran your code and it doesnt ask me which folder I would like to use. maybe Im missing something


    Quote Originally Posted by spitfireblue View Post
    That is what it does... however I have amended it slightly so that you only have to put the folder location in once.

    Please Login or Register  to view this content.
    The blue highlighted code opens each file in the folder and then closes and saves it at the completion of your code, but you can take them out if you need.

  6. #6
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Choose a Folder and loop a sub

    Oh... I understand now. You want to select the folder. Try this...

    Please Login or Register  to view this content.

  7. #7
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: Choose a Folder and loop a sub

    @ spitfireblue
    Hi
    i just wanted to say that I found this " Shell " " BrowseForFolder " thing a nice alternative to other ways to get at files and so used it effectively....
    http://www.mrexcel.com/forum/excel-q...ml#post4427500
    So I wanted to mainly say thanks, but also to say in passing that your Default Path is not specified or declared ( OpenAt ). But that is not a problem if the OP has not got Option Explicit as it then just takes it as "" and goes by the default )

    @ smartbuyer
    The code i did at that reference I gave above allows you to select which files in the Folder you want to do stuff on. That may be of interest

    Note also what was said in that other Thread of yours:
    http://www.excelforum.com/excel-prog...ml#post4306686
    Quote Originally Posted by JLGWhiz View Post
    You did not specify a path or directory name, so it is assumed that the Master workbook will be in the same folder as the files and the Master workbook will host the code.......
    I think if you had taken note of that you would have seen that you had your problem here very close to solved.
    Maybe the next time when you start a similar thread you should copy the URL Link from above in the small Browser Window and post in the Thread at the start. This helps us not to repeat what others have done for you.....
    Quote Originally Posted by smartbuyer View Post
    .....
    Couldnt find anything online that allows me to paste my existing sub. ....
    ..I think in the other Thread that is more or less what JLGWhiz showed you
    Thanks
    Alan
    Last edited by Doc.AElstein; 02-12-2016 at 11:41 AM.
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

+ 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. Choose a Folder and Loop a Sub for all files in the chosen folder
    By smartbuyer in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-11-2016, 10:57 PM
  2. [SOLVED] Choose a folder and loop through all files in the chosen folder
    By smartbuyer in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-10-2016, 11:19 PM
  3. [SOLVED] Loop Through Folder, Create Emails with Sub Folder Names in Subject, Attach files in sub
    By Rschwar23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2015, 10:06 AM
  4. Replies: 12
    Last Post: 03-09-2015, 05:52 PM
  5. Replies: 1
    Last Post: 10-18-2014, 05:04 PM
  6. [SOLVED] Save as PDF to a folder I choose
    By vbanewbie! in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-17-2013, 04:02 PM
  7. How to choose a folder
    By Ctech in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-04-2005, 08:40 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