Hi,
I don't know enough vba to write all (or much at all) of my own code, so I hunt and peck around the internet to find code that works for my needs. I found two pieces of code that work as desired when used individually, but not when put together. The first piece of code is written to loop through all files in a folder and "do something" to each of them. The second piece of code is written to combine multiple workbooks into a single workbook. When combined, the code almost works perfectly, but it does throw an error at the very end. Actually, I think the end result is (combined file) good. I just want to know why there is an error, how to get rid of it, and if anyone can help me fix the problem.
Below, I will provide the sample code that I found for each task, and then I will include my attempt at combining them to work together.
Code to loop through all files in a folder and do something:
Please Login or Register to view this content.
Code to combine multiple workbooks into a single workbook:
Please Login or Register to view this content.
Here is my attempt at combining the two pieces of code:
Please Login or Register to view this content.
When I run the combined code, the end result a combined file that looks good. I think it is doing what I want. BUT, at the end, the following error is thrown:
Run-time error '5':
Invalid procedure call or argument
... and when I debug, the following line (directly above the final Loop, and directly below DoEvents) is highlighted:
myFile = Dir
How can I fix this problem?
Bookmarks