My VBA code needs to import text files and put each one into a new worksheet. I'm currently using the following code to accomplish this:
Code
Do
Application.DisplayAlerts = False
Sheets.Add
ChDir Path
Workbooks.Open Filename:=Path & Name
ActiveSheet.UsedRange.Copy
ActiveWorkbook.Close
Workbooks("Project.xls").Worksheets(1).Activate
ActiveSheet.Paste
i = i + 1
Application.CutCopyMode = False
Loop
Display More
For some reason, it won't run in runtime mode, but it does work in break mode when I step through it. When I run it in runtime mode, I get a "Run-time error '1004': Microsoft Office Excel cannot paste the data." message displayed.
If someone could explain why that little procedure won't work in runtime and why it does in break mode, I'd appreciate it.
Thanks!