Hello all,
I am trying to automate excel to open n number of file into a directory.
The target is to open all the *.txt file which are in a directory, then grab a couple of values and copy them into an output *.xls file then open the next *.txt file and son on.
The following sub does the job for one file only. What I need is to automate the procedure with a do loop. I have started it but I am struggling so need your help guys.
Thanks
francois
Sub LoadData()
Attribute LoadData.VB_Description = "Macro recorded 08/08/2004 by"
Attribute LoadData.VB_ProcData.VB_Invoke_Func = " \n14"
Dim filename1, WorkingPath As String
WorkingPath = ActiveWorkbook.PATH
With Application
.DefaultFilePath = WorkingPath
End With
ChDir WorkingPath
filename1 = Application.GetOpenFilename("Data File PRN Data(*.txt), *.txt")
Workbooks.OpenText Filename:=filename1, Origin:= _
xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1)), TrailingMinusNumbers:=True
ActiveWindow.WindowState = xlNormal
With ActiveWindow
.Top = 115.75
.Left = 253.75
End With
Range("A1:I8000").Select
Selection.Copy
Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True
Windows("LogFile.xls").Activate
Range("A1").Select
ActiveSheet.Paste
End Sub
I am trying to automate excel to open n number of file into a directory.
The target is to open all the *.txt file which are in a directory, then grab a couple of values and copy them into an output *.xls file then open the next *.txt file and son on.
The following sub does the job for one file only. What I need is to automate the procedure with a do loop. I have started it but I am struggling so need your help guys.
Thanks
francois
Sub LoadData()
Attribute LoadData.VB_Description = "Macro recorded 08/08/2004 by"
Attribute LoadData.VB_ProcData.VB_Invoke_Func = " \n14"
Dim filename1, WorkingPath As String
WorkingPath = ActiveWorkbook.PATH
With Application
.DefaultFilePath = WorkingPath
End With
ChDir WorkingPath
filename1 = Application.GetOpenFilename("Data File PRN Data(*.txt), *.txt")
Workbooks.OpenText Filename:=filename1, Origin:= _
xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1)), TrailingMinusNumbers:=True
ActiveWindow.WindowState = xlNormal
With ActiveWindow
.Top = 115.75
.Left = 253.75
End With
Range("A1:I8000").Select
Selection.Copy
Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True
Windows("LogFile.xls").Activate
Range("A1").Select
ActiveSheet.Paste
End Sub