Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
run time error 1004 general odbc error excel 2003 vba | Excel Programming | |||
Visual Basic Error Run Time Error, Type Mismatch | Excel Discussion (Misc queries) | |||
Error handling error # 1004 Run-time error | Excel Programming | |||
Conditional Formatting - Run Time Error '13' Type Mismatch Error | Excel Programming | |||
run-time error '1004': Application-defined or object-deifined error | Excel Programming |