Code: Select all
Sub Macro1()
' Macro1 Macro
Dim strPath As Variant, i As Integer
Dim fName As String
strPath = Application.GetOpenFilename("Text files(*.txt*),*.txt*", _
Title:="Please select text files.", MultiSelect:=True)
If TypeName(strPath) = "Boolean" Then Exit Sub
For i = 1 To UBound(strPath)
fName = VBA.Left(strPath(i), InStr(strPath(i), ".")) & "xlsx"
Workbooks.OpenText Filename:=strPath(i), Origin:=874, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, Comma:=False, _
Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3 _
, 1), Array(4, 2), Array(5, 9), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), Array(10, _
1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array(16, 1), _
Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 3), Array(22, 4)), _
TrailingMinusNumbers:=True
Next i
Windows("incentive_B.txt").Activate
Application.Goto Reference:="OFFSET(R1C1,1,,COUNTA(C1)-1,COUNTA(R2))"
Selection.Copy
Windows("incentive_A.txt").Activate
Application.Goto Reference:="OFFSET(R1C1,COUNTA(C1)+1,,,)"
ActiveSheet.Paste
Windows("incentive_C.txt").Activate
Application.Goto Reference:="OFFSET(R1C1,1,,COUNTA(C1)-1,COUNTA(R2))"
Selection.Copy
Windows("incentive_A.txt").Activate
Application.Goto Reference:="OFFSET(R1C1,COUNTA(C1)+1,,,)"
ActiveSheet.Paste
Windows("incentive_D.txt").Activate
Application.Goto Reference:="OFFSET(R1C1,1,,COUNTA(C1)-1,COUNTA(R2))"
Selection.Copy
Windows("incentive_A.txt").Activate
Application.Goto Reference:="OFFSET(R1C1,COUNTA(C1)+1,,,)"
ActiveSheet.Paste
Sheets("incentive_A").Name = "incentive"
'ActiveWorkbook.SaveAs Filename:=fName, FileFormat:= _
'xlOpenXMLWorkbook, CreateBackup:=False
'ActiveWorkbook.Close False
MsgBox "Finish."
End Sub