run time error 53
I am using a macro to open up unknown files from one folder, put them
in another and change the name. what happenes is when the folder runs
out of files it stops the macro mid point. I need to get past this
error with out a msg box or any stoppage.
Do
ChDir "C:\Documents and Settings\Owner\Desktop\Data log trending
Version 2.0"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("C:\Documents and Settings\Owner\Desktop
\Data log trending Version 2.0\Data log files (by machine)\P124\TXT")
Set tmp = Workbooks.Add
Set myfiles = f.Files
counter = 1
For Each fc In myfiles
tmp.Sheets(1).Cells(counter, 1).Value = fc.Name
tmp.Sheets(1).Cells(counter, 2).Value = fc.datelastmodified
counter = counter + 1
Next
tmp.Sheets(1).Columns("B:B").EntireColumn.AutoFit
tmp.Sheets(1).Range(Selection, Selection.End(xlToRight)).Select
tmp.Sheets(1).Range(Selection, Selection.End(xlDown)).Select
Set sortrange = Selection
For Count = 1 To 1
Set f2 = fso.GetFile("C:\Documents and Settings\Owner\Desktop
\Data log trending Version 2.0\Data log files (by machine)\P124\TXT\"
& tmp.Sheets(1).Cells(Count, 1).Value)
f2.Move ("C:\Documents and Settings\Owner\Desktop\Data log
trending Version 2.0\Data log files (by machine)\P124\Known txt files
\" & tmp.Sheets(1).Cells(Count, 1).Value)
Next Count
tmp.Close False
Set tmp = Nothing
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("C:\Documents and Settings\Owner\Desktop
\Data log trending Version 2.0\Data log files (by machine)\P124\DAT")
Set tmp = Workbooks.Add
Set myfiles = f.Files
counter = 1
For Each fc In myfiles
tmp.Sheets(1).Cells(counter, 1).Value = fc.Name
tmp.Sheets(1).Cells(counter, 2).Value = fc.datelastmodified
counter = counter + 1
Next
tmp.Sheets(1).Columns("B:B").EntireColumn.AutoFit
tmp.Sheets(1).Range(Selection, Selection.End(xlToRight)).Select
tmp.Sheets(1).Range(Selection, Selection.End(xlDown)).Select
Set sortrange = Selection
For Count = 1 To 1
Set f2 = fso.GetFile("C:\Documents and Settings\Owner\Desktop
\Data log trending Version 2.0\Data log files (by machine)\P124\DAT\"
& tmp.Sheets(1).Cells(Count, 1).Value)
On Error Resume Next
f2.Move ("C:\Documents and Settings\Owner\Desktop\Data log
trending Version 2.0\Data log files (by machine)\P124\Known dat files
\" & tmp.Sheets(1).Cells(Count, 1).Value)
Next Count
tmp.Close False
Set tmp = Nothing
s1 = "C:\Documents and Settings\Owner\Desktop\Data log trending
Version 2.0\Data log files (by machine)\P124\Known txt files\"
sName = Dir(s1 & "*.*")
i = 0
Do While sName < ""
i = i + 1
Name s1 & sName As s1 & i & ".txt"
sName = Dir()
Loop
s1 = "C:\Documents and Settings\Owner\Desktop\Data log trending
Version 2.0\Data log files (by machine)\P124\Known dat files\"
sName = Dir(s1 & "*.*")
i = 0
Do While sName < ""
i = i + 1
Name s1 & sName As s1 & i & ".dat"
sName = Dir()
Loop
Please help
|