Hi
I've been doing some searching over the forum but the solutions is not what I need. Basically I need to import txt files with two different methods, one is delimited the other is Fixedwith -using the array code as below - (due to the system where they come from are different), both needs to be in the same workbook (name Legal to Export) but in the different sheets name as the system from they come from (SAP and JBA). If I record the macro I the get the below codes, so the idea is merged them and instead using the Worksbook open method get something to joint them. In addition the source files will not be in the same path, so this is why I modified the macro to use the GetOpenFilename.
I've been doing some searching over the forum but the solutions is not what I need. Basically I need to import txt files with two different methods, one is delimited the other is Fixedwith -using the array code as below - (due to the system where they come from are different), both needs to be in the same workbook (name Legal to Export) but in the different sheets name as the system from they come from (SAP and JBA). If I record the macro I the get the below codes, so the idea is merged them and instead using the Worksbook open method get something to joint them. In addition the source files will not be in the same path, so this is why I modified the macro to use the GetOpenFilename.
Code:
Sub JBA()
Dim vFileName
vFileName = Application.GetOpenFilename("Text Files (*.txt),*.txt")
Application.ScreenUpdating = False
Workbooks.OpenText Filename:=vFileName _
, Origin:=xlWindows, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array( _
Array(0, 1), Array(4, 2), Array(12, 1), Array(25, 1), Array(77, 1), Array(82, 2), Array(120 _
, 1), Array(141, 1), Array(173, 1), Array(205, 1)), TrailingMinusNumbers:=True
Cells.Select
Cells.EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub
Code:
Sub SAP()
Dim vFileName
vFileName = Application.GetOpenFilename("Text Files (*.txt),*.txt")
Workbooks.OpenText Filename:=vFileName _
, 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), Array(5, 1), Array(6, 1), Array(7, 1)), _
TrailingMinusNumbers:=True
Cells.Select
Cells.EntireColumn.AutoFit
End Sub