Apply Macro to All Files in Folder

  • Hey guys,


    So I'm trying to process an entire folder with one macro. I'm starting with text files, converting to xls, then doing some adjusting.


    The problem seems to be if I use a specific file name the macro will act only on that file in the folder, even though I have a loop set up.


    I am an absolute beginner, I know literally nothing about writting code, I've been using the macro recorder and copying bits and pieces that I've found online, nothing seems to be working though



    So what I tried, instead of using a specific file name was using a star, this sort of worked, in that it opened other files, but the actions from the macro only applied to the first file in the folder, then it would close this file, re-open this same file and another file, and again only apply the macro to the first file.


    To fix this I tried adding Kill to delete the file, but this ended with me deleting everything in the folder, which is not ideal.


    So I'm a little lost here.


    Again, I would like to re-iterate that I am a complete beginner and I know absolutely nothing about code writting. That being said I would really appreciate any kind of help.


    Thanks guys.

  • Re: Apply Macro to All Files in Folder


    Hi


    You are only opening the one workbook Workbooks.Open Filename:="C:\Users\Ben\Desktop\Cell Making Spreadsheet.xlsx" _


    You need to add variable to the file you are opening

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!