+ Reply to Thread
Results 1 to 14 of 14

Problems with looping macro through specific folder

  1. #1
    Registered User
    Join Date
    07-22-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    85

    Problems with looping macro through specific folder

    Hi, i have a macro to clear contents on all sheets on Col A.

    Please Login or Register  to view this content.
    this macro works when i place it in a specifc workbook to run it. However when i try calling it using this macro to loop through all workbooks in specific folder it doesn't work. The looping macro is as below. Can someone show me where i went wrong? Master represents the workbook which the looping macro is running from and Book1 and Book2 are the files that i want to clear contents with.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Problems with looping macro through specific folder

    Alittle trick I learned from snb,
    Make sure that you only have the files you want to loop through in the folder. Change the folder path to suit your situation. Also make sure the master file in not in the folder to be looped through.

    Please Login or Register  to view this content.
    Edit, I just saw that you named the macro clearcontents, you should not do that. I would change the name
    Last edited by JapanDave; 09-07-2012 at 11:20 PM.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Registered User
    Join Date
    07-22-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    85

    Re: Problems with looping macro through specific folder

    Hi i tried your macro but there seems to be an error

    Please Login or Register  to view this content.
    However essentially i want to learn how to use a macro in a master workbook to loop pre-exisiting macros by call the sub procs, is there anyway to work around it this way?

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Problems with looping macro through specific folder

    Hi, I amended JapanDave's code and there are no compile errors.
    Please Login or Register  to view this content.

    kchm, don't forget to change your path here:
    Please Login or Register  to view this content.
    Last edited by Mordred; 09-08-2012 at 12:10 AM.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  5. #5
    Registered User
    Join Date
    07-22-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    85

    Re: Problems with looping macro through specific folder

    Hi thanks for your help i think the macro works but i the macro does not save the results of the clearcontents how do i add that?

  6. #6
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Problems with looping macro through specific folder

    Try
    Please Login or Register  to view this content.

  7. #7
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Problems with looping macro through specific folder

    Thanks Mordred,
    Sorry, I forgot to take the end with out from your code.
    Get rid of the macro that is called "clearcontents", this is causing problems.
    Try this,
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-22-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    85

    Re: Problems with looping macro through specific folder

    Thanks the code now works, is there a way to code so that i can just call sub procedures because i still have other macros i want to loop through folders?

  9. #9
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Problems with looping macro through specific folder

    Just type in the procedure names where you want them run.

  10. #10
    Registered User
    Join Date
    07-22-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    85

    Re: Problems with looping macro through specific folder

    Please Login or Register  to view this content.
    something like this? where clear contents is


    Please Login or Register  to view this content.

  11. #11
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Problems with looping macro through specific folder

    Just use,
    But, why do you need to call a macro?
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    07-22-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    85

    Re: Problems with looping macro through specific folder

    because i still have other macros to run and i am not very proficient at macros hence i want a general macro that links several subprocedures together, instead of prompting the forum boards continually. Thanks modred and dave

  13. #13
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Problems with looping macro through specific folder

    No problem, if the thread has given you the answer please don't forget to say thanks by clicking the star in the left hand corner and mark the thread solved.

  14. #14
    Registered User
    Join Date
    07-22-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    85

    Re: Problems with looping macro through specific folder

    Hi, i have tried again using call sub method however the is an error on the sub c()

    Please Login or Register  to view this content.
    can someone clarify why there is an error when calling this sub proc?

    actually i have other sub sub procs such as trim all cells and also adding a date column based on a cell reference that is why i am more comfortable using a looping macro through folder and then calling sub procs thanks a lot

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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