PDA

View Full Version : Sleeper: Macro loop issues



carobiscuit
09-28-2012, 10:44 AM
Hello,

I have set up formatting and opening/closing macros for files to append to a master database file. I am new to VBA and can't see a way to keep this from going back to the FIRST macro that opens all .csv files rather than the 3 following the "for each" statement.


Sub ReportMacro()
Dim ws As Worksheet
Application.Run "PERSONAL.XLSB!importfile" // i want this to run one time only
For Each ws In ActiveWorkbook.Worksheets
Application.Run "PERSONAL.XLSB!Report"
Application.Run "PERSONAL.XLSB!AppendData"
Application.Run "PERSONAL.XLSB!closeworksheet"
Next ws //I want this to loop back to "Report" macro
End Sub

Thanks so much for any help

Bob Phillips
09-28-2012, 12:29 PM
It doesn't look as though it should, so maybe the whole macro is being invoked by one of those macros.

But how does each sheet matter to those macros, they are just being called as is, so won't they just do the same thing over and over?

carobiscuit
09-28-2012, 02:27 PM
I plan to have a folder where files will be exported over a period, then at the end of the period i want this macro to add all the data from the files onto a master db. I'll go and move or delete the files after that and start all over. If there's a better way to get all files opened, edited, and appended, then closed, I'm all for that...