Import multiple txt files (different format) to the same workbook in different sheets

PVA0724

New Member
Joined
Apr 21, 2012
Messages
48
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.

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
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top