Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
move unknown files
I would like to move files from one folder to another but I do not
know the names. I would like to move them by date modified (oldest ones are moved to the other folder). It is important that they do not remain in the first folder. Also I have a macro that is doing a number of things how can I loop the entire marco? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
move unknown files
You can use Windows Explorer to view the details of files in specific folders
and then drag them from one folder to another faster than I can write a macro to do it. As for the looping of the macro, you would need to post the existing code and then give a little more detail about how you want it to loop. " wrote: I would like to move files from one folder to another but I do not know the names. I would like to move them by date modified (oldest ones are moved to the other folder). It is important that they do not remain in the first folder. Also I have a macro that is doing a number of things how can I loop the entire marco? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
move unknown files
I have 10,000 files that I need to move into the this folder 5 at a
time as part of my macro. The macro I have opens up five "dat" files and five "txt" files. It then puts the files into a spread sheet which pulls a bunch of info out of them and then copies it al into a trend chart. Once it is copied into the trend chart the macro closes everything so I can start all over again. The problem is that I manually hve to transfer the five files into the folder that the macro pulls them from and that is why I would like a macro that can put the unkown files into this folder 5 at a time. here is the macro I am using Sub P123_data_entry() ' ' P123_data_entry Macro ' Macro recorded 2/7/2007 by owner ' ' Keyboard Shortcut: Ctrl+a 'ChDir "C:\Documents and Settings\owner\Desktop\Trending" s1 = "C:\Documents and Settings\owner\Desktop\Trending\P123\Known dat files\" s2 = "C:\Documents and Settings\owner\Desktop\Trending\P123\Known txt files\" sName = Dir(s1 & "*.*") i = 0 Do While sName < "" i = i + 1 Name s1 & sName As s1 & i & ".dat" sName = Dir() Loop sName = Dir(s2 & "*.*") i = 0 Do While sName < "" i = i + 1 Name s2 & sName As s2 & i & ".txt" sName = Dir() Loop ChDir _ "C:\Documents and Settings\owner\Desktop\Trending\P123\Known txt files" Workbooks.OpenText Filename:= _ "C:\Documents and Settings\owner\Desktop\Trending\P123\Known txt files\1.txt" _ , Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier _ :=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:= _ False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array _ (1, 1), Array(2, 1), Array(3, 1)) Cells.Select Selection.Copy Windows("datalog info.xls").Activate Sheets("Datalog1").Select Range("A1").Select ActiveSheet.Paste Windows( _ "1.txt"). _ Activate Range("J7").Select Application.CutCopyMode = False ActiveWindow.Close ChDir _ "C:\Documents and Settings\owner\Desktop\Trending\P123\Known txt files" Workbooks.OpenText Filename:= _ "C:\Documents and Settings\owner\Desktop\Trending\P123\Known txt files\2.txt" _ , Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier _ :=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:= _ False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array _ (1, 1), Array(2, 1), Array(3, 1)) Cells.Select Selection.Copy Windows("datalog info.xls").Activate Sheets("Datalog2").Select Range("A1").Select ActiveSheet.Paste Windows( _ "2.txt"). _ Activate Range("K15").Select Application.CutCopyMode = False ActiveWindow.Close ChDir _ "C:\Documents and Settings\owner\Desktop\Trending\P123\Known txt files" Workbooks.OpenText Filename:= _ "C:\Documents and Settings\owner\Desktop\Trending\P123\Known txt files\3.txt" _ , Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier _ :=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:= _ False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array _ (1, 1), Array(2, 1), Array(3, 1)) Cells.Select Selection.Copy Windows("datalog info.xls").Activate Sheets("Datalog3").Select Range("A1").Select ActiveSheet.Paste Cells.Select Windows( _ "3.txt"). _ Activate Range("H15").Select Application.CutCopyMode = False ActiveWindow.Close ChDir _ "C:\Documents and Settings\owner\Desktop\Trending\P123\Known txt files" Workbooks.OpenText Filename:= _ "C:\Documents and Settings\owner\Desktop\Trending\P123\Known txt files\4.txt" _ , Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier _ :=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:= _ False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array _ (1, 1), Array(2, 1), Array(3, 1)) Cells.Select Selection.Copy Windows("datalog info.xls").Activate Sheets("Datalog4").Select Range("A1").Select ActiveSheet.Paste Windows( _ "4.txt"). _ Activate Range("J22").Select Application.CutCopyMode = False ActiveWindow.Close ChDir _ "C:\Documents and Settings\owner\Desktop\Trending\P123\Known txt files" Workbooks.OpenText Filename:= _ "C:\Documents and Settings\owner\Desktop\Trending\P123\Known txt files\5.txt" _ , Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier _ :=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:= _ False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array _ (1, 1), Array(2, 1), Array(3, 1), Array(4, 1)) Cells.Select Selection.Copy Windows("datalog info.xls").Activate Sheets("Datalog5").Select Range("A1").Select ActiveSheet.Paste Windows( _ "5.txt"). _ Activate Range("K21").Select Application.CutCopyMode = False ActiveWindow.Close Workbooks.OpenText Filename:= _ "C:\Documents and Settings\owner\Desktop\Trending\P123\Known dat files\1.dat", _ Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _ xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _ Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1) Cells.Select Selection.Copy Windows("datalog info.xls").Activate Sheets("DAT1").Select Range("A1").Select ActiveSheet.Paste Windows( _ "1.dat"). _ Activate Range("K21").Select Application.CutCopyMode = False ActiveWindow.Close Workbooks.OpenText Filename:= _ "C:\Documents and Settings\owner\Desktop\Trending\P123\Known dat files\2.dat", _ Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _ xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _ Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1) Cells.Select Selection.Copy Windows("datalog info.xls").Activate Sheets("DAT2").Select Range("A1").Select ActiveSheet.Paste Windows( _ "2.dat"). _ Activate Range("K21").Select Application.CutCopyMode = False ActiveWindow.Close Workbooks.OpenText Filename:= _ "C:\Documents and Settings\owner\Desktop\Trending\P123\Known dat files\3.dat", _ Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _ xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _ Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1) Cells.Select Selection.Copy Windows("datalog info.xls").Activate Sheets("DAT3").Select Range("A1").Select ActiveSheet.Paste Windows( _ "3.dat"). _ Activate Range("K21").Select Application.CutCopyMode = False ActiveWindow.Close Workbooks.OpenText Filename:= _ "C:\Documents and Settings\owner\Desktop\Trending\P123\Known dat files\4.dat", _ Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _ xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _ Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1) Cells.Select Selection.Copy Windows("datalog info.xls").Activate Sheets("DAT4").Select Range("A1").Select ActiveSheet.Paste Windows( _ "4.dat"). _ Activate Range("K21").Select Application.CutCopyMode = False ActiveWindow.Close Workbooks.OpenText Filename:= _ "C:\Documents and Settings\owner\Desktop\Trending\P123\Known dat files\5.dat", _ Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _ xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _ Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1) Cells.Select Selection.Copy Windows("datalog info.xls").Activate Sheets("DAT5").Select Range("A1").Select ActiveSheet.Paste Windows( _ "5.dat"). _ Activate Range("J19").Select Application.CutCopyMode = False ActiveWindow.Close ActiveWindow.ScrollWorkbookTabs Sheets:=-1 ActiveWindow.ScrollWorkbookTabs Sheets:=-1 ActiveWindow.ScrollWorkbookTabs Sheets:=-1 Range("E5001").Select Sheets("Info").Select Range("A2:AC6").Select Columns("U:U").EntireColumn.AutoFit ActiveWindow.SmallScroll ToRight:=5 Range("A2:Ag6").Select Range("Ag2").Activate Application.CutCopyMode = False Selection.Copy Windows("P123 Trend Chart.xls").Activate Range("B2").Select Windows("P123 Trend Chart.xls").Activate Windows("datalog info.xls").Activate ActiveWindow.SmallScroll ToRight:=-23 Range("A2:Ag6").Select Selection.Copy Windows("P123 Trend Chart.xls").Activate Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Rows("2:2").Select Rows("2:6").Select Application.CutCopyMode = False Selection.Insert Shift:=xlDown Selection.Interior.ColorIndex = xlNone Range("B2").Select Windows("datalog info.xls").Activate Windows("test2.xls").Activate Windows("datalog info.xls").Activate Windows("datalog info.xls").Activate Range("N6").Select Application.CutCopyMode = False Sheets("Sheet1").Select Columns("N:O").Select Selection.Copy Windows("RORs.xls").Activate Sheets("Sheet1").Select Columns("A:B").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Application.ScreenUpdating = False lastrow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row For row_index = lastrow - 1 To 1 Step -1 If Cells(row_index, 2).Value = "" Then Rows(row_index).Delete End If Next Application.ScreenUpdating = True Sheets("Sheet2").Select Range("A2").Select Windows("datalog info.xls").Activate Range("N6").Select Application.CutCopyMode = False Sheets("Sheet2").Select Columns("N:O").Select Selection.Copy Windows("RORs.xls").Activate Sheets("Sheet2").Select Columns("A:B").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Application.ScreenUpdating = False lastrow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row For row_index = lastrow - 1 To 1 Step -1 If Cells(row_index, 2).Value = "" Then Rows(row_index).Delete End If Next Application.ScreenUpdating = True Sheets("Sheet3").Select Range("A2").Select Windows("datalog info.xls").Activate Range("N5").Select Application.CutCopyMode = False Sheets("Sheet3").Select Columns("N:O").Select Selection.Copy Windows("RORs.xls").Activate Sheets("Sheet3").Select Columns("A:B").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Application.ScreenUpdating = False lastrow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row For row_index = lastrow - 1 To 1 Step -1 If Cells(row_index, 2).Value = "" Then Rows(row_index).Delete End If Next Application.ScreenUpdating = True Range("a2").Select Sheets("Sheet4").Select Windows("test2.xls").Activate Windows("datalog info.xls").Activate Range("N16").Select Application.CutCopyMode = False Sheets("Sheet4").Select Columns("N:O").Select Selection.Copy Windows("RORs.xls").Activate Sheets("Sheet4").Select Columns("A:B").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Application.ScreenUpdating = False lastrow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row For row_index = lastrow - 1 To 1 Step -1 If Cells(row_index, 2).Value = "" Then Rows(row_index).Delete End If Next Application.ScreenUpdating = True Range("D2").Select Sheets("Sheet5").Select Windows("test2.xls").Activate Windows("datalog info.xls").Activate Range("N16").Select Application.CutCopyMode = False Sheets("Sheet5").Select Columns("N:O").Select Selection.Copy Windows("RORs.xls").Activate Sheets("Sheet5").Select Columns("A:B").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Application.ScreenUpdating = False lastrow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row For row_index = lastrow - 1 To 1 Step -1 If Cells(row_index, 2).Value = "" Then Rows(row_index).Delete End If Next Application.ScreenUpdating = True Range("A2").Select Windows("datalog info.xls").Activate Windows("P123 Trend Chart.xls").Activate ActiveWindow.SmallScroll ToRight:=24 Windows("RORs.xls").Activate Sheets("Sheet1").Select Range("A2:B2").Select Application.CutCopyMode = False Selection.Copy Windows("P123 Trend Chart.xls").Activate Range("AE7:AF7").Select ActiveSheet.Paste Windows("RORs.xls").Activate Range("A3:B3").Select Application.CutCopyMode = False Selection.Copy Windows("P123 Trend Chart.xls").Activate Range("AG7:AH7").Select ActiveSheet.Paste Range("AE8").Select Windows("RORs.xls").Activate Sheets("Sheet2").Select Range("A2:B2").Select Application.CutCopyMode = False Selection.Copy Windows("P123 Trend Chart.xls").Activate Range("AE8:AF8").Select ActiveSheet.Paste Range("AG8").Select Windows("RORs.xls").Activate Range("A3:B3").Select Application.CutCopyMode = False Selection.Copy Windows("P123 Trend Chart.xls").Activate Range("AG8:AH8").Select ActiveSheet.Paste Range("AE9").Select Windows("RORs.xls").Activate Range("A4").Select Application.CutCopyMode = False Sheets("Sheet3").Select Range("A2:B2").Select Selection.Copy Windows("P123 Trend Chart.xls").Activate Range("AE9:AF9").Select ActiveSheet.Paste Range("AG9").Select Windows("RORs.xls").Activate Range("A3:B3").Select Application.CutCopyMode = False Selection.Copy Windows("P123 Trend Chart.xls").Activate Range("AG9:AH9").Select ActiveSheet.Paste Range("AE10").Select Windows("RORs.xls").Activate Range("A6").Select Application.CutCopyMode = False Sheets("Sheet4").Select Range("A2:B2").Select Selection.Copy Windows("P123 Trend Chart.xls").Activate Range("AE10:AF10").Select ActiveSheet.Paste Range("AG10").Select Windows("datalog info.xls").Activate Windows("RORs.xls").Activate Range("A3:B3").Select Application.CutCopyMode = False Selection.Copy Windows("datalog info.xls").Activate Windows("P123 Trend Chart.xls").Activate Range("AG10:AH10").Select ActiveSheet.Paste Windows("RORs.xls").Activate Range("D10").Select Application.CutCopyMode = False Sheets("Sheet5").Select Range("A2:B2").Select Selection.Copy Windows("P123 Trend Chart.xls").Activate Range("AE11:AF11").Select ActiveSheet.Paste Range("AG11").Select Windows("RORs.xls").Activate Range("A3:B3").Select Application.CutCopyMode = False Selection.Copy Windows("P123 Trend Chart.xls").Activate Range("AG11:AH11").Select ActiveSheet.Paste Windows("RORs.xls").Activate Range("A6").Select Application.CutCopyMode = False Windows("test2.xls").Activate Windows("RORs.xls").Activate Range("A2:B3").Select Selection.Delete Shift:=xlUp Sheets("Sheet4").Select Range("A2:B3").Select Selection.Delete Shift:=xlUp Sheets("Sheet3").Select Range("A2:B3").Select Selection.Delete Shift:=xlUp Sheets("Sheet2").Select Range("A2:B3").Select Selection.Delete Shift:=xlUp Sheets("Sheet1").Select Range("A2:B3").Select Selection.Delete Shift:=xlUp Range("C4").Select Windows("P123 Trend Chart.xls").Activate Windows("datalog info.xls").Activate ActiveWindow.ScrollWorkbookTabs Sheets:=-1 ActiveWindow.ScrollWorkbookTabs Sheets:=-1 ActiveWindow.ScrollWorkbookTabs Sheets:=-1 ActiveWindow.ScrollWorkbookTabs Sheets:=-1 ActiveWindow.ScrollWorkbookTabs Sheets:=-1 ActiveWindow.ScrollWorkbookTabs Sheets:=-1 ActiveWindow.ScrollWorkbookTabs Sheets:=-1 Sheets("Datalog1").Select Selection.ClearContents Sheets("Datalog2").Select Selection.ClearContents Sheets("Datalog3").Select Selection.ClearContents Sheets("Datalog4").Select Selection.ClearContents Sheets("Datalog5").Select Selection.ClearContents Sheets("DAT1").Select Selection.ClearContents Sheets("DAT2").Select Selection.ClearContents Sheets("DAT3").Select Selection.ClearContents Sheets("DAT4").Select Selection.ClearContents Sheets("DAT5").Select Selection.ClearContents Sheets("Datalog2").Select ActiveWindow.ScrollWorkbookTabs Sheets:=-1 ActiveWindow.ScrollWorkbookTabs Sheets:=-1 ActiveWindow.ScrollWorkbookTabs Sheets:=-1 Windows("test2.xls").Activate On Error Resume Next Kill "C:\Documents and Settings\owner\Desktop\Trending\P123\Known txt files\*.txt" On Error GoTo 0 On Error Resume Next Kill "C:\Documents and Settings\owner\Desktop\Trending\P123\Known dat files\*.dat" On Error GoTo 0 MsgBox "P123 Finished" End Sub |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
move unknown files
If I cannot get the unknown files to transfer to the specific folder I
need them in then I don't need to loop the macro |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Unknown excel backup files created in network directory | Excel Discussion (Misc queries) | |||
rename unknown named files | Excel Programming | |||
Move files | Excel Programming | |||
Macro to add cells from unknown number of files | Excel Programming | |||
FTP Accessing remote files where filenames are unknown | Excel Programming |