I
ianripping
I have this code. It generates a list of files in the c:\ Directory.
then opens these files and copies the information to Book1.xls.
It only does this for the firt file listed. At most there are going t
be 8 xls files in the root directory at all time. I could repeat thi
code 8 time which would be no problem. But If i did this and there wer
only 3 files in the directory, it would come up with an error messag
asking if I want to debug.
Could I therefore use an IF command that states that is ther is no fil
name in Cell A(Whatever) then the macro will stop?
I know its a bit long whinded but any help would be much appreciated!
Sub ListFiles()
Range("A:A").Select
Selection.Delete
Range("A1").Select
F = Dir("C:\*.XLS")
Do While Len(F) > 0
ActiveCell.Formula = F
ActiveCell.Offset(1, 0).Select
F = Dir()
Loop
Range("B1").Select
ActiveCell.FormulaR1C1 = "=""C:\"""
Range("C1").Select
ActiveCell.FormulaR1C1 = "=RC[-1]&RC[-2]"
Workbooks.Open Filename:=Range("C1").Value
ActiveWindow.WindowState = xlNormal
Sheets("Sheet1").Select
Sheets("Sheet1").Copy Before:=Workbooks("Book1.xls").Sheets(2)
Sheets("Sheet1").Select
ActiveWindow.WindowState = xlMaximized
MsgBox ("Completed Copying")
End Su
then opens these files and copies the information to Book1.xls.
It only does this for the firt file listed. At most there are going t
be 8 xls files in the root directory at all time. I could repeat thi
code 8 time which would be no problem. But If i did this and there wer
only 3 files in the directory, it would come up with an error messag
asking if I want to debug.
Could I therefore use an IF command that states that is ther is no fil
name in Cell A(Whatever) then the macro will stop?
I know its a bit long whinded but any help would be much appreciated!
Sub ListFiles()
Range("A:A").Select
Selection.Delete
Range("A1").Select
F = Dir("C:\*.XLS")
Do While Len(F) > 0
ActiveCell.Formula = F
ActiveCell.Offset(1, 0).Select
F = Dir()
Loop
Range("B1").Select
ActiveCell.FormulaR1C1 = "=""C:\"""
Range("C1").Select
ActiveCell.FormulaR1C1 = "=RC[-1]&RC[-2]"
Workbooks.Open Filename:=Range("C1").Value
ActiveWindow.WindowState = xlNormal
Sheets("Sheet1").Select
Sheets("Sheet1").Copy Before:=Workbooks("Book1.xls").Sheets(2)
Sheets("Sheet1").Select
ActiveWindow.WindowState = xlMaximized
MsgBox ("Completed Copying")
End Su