Importing .tab file using Import wizard

juice_box

New Member
Joined
Dec 9, 2015
Messages
6
Trying to import a .tab file where specific columns are formatted as text. This is because there is data in the columns where a 0 is at the beginning ie 07256. I want to keep that 0. I tried using the macro recorder and then edited to fit what i need. The 0 keeps dropping off. Here is the code. columns i need in text are 4, 5, and 13. What can I do so the columns stay in text.

Sub Format_File()


Application.ScreenUpdating = False
thisfile = ActiveWorkbook.Name


Dim thatfile As String
Dim DRASfilename As String




DRAS2XXXX = Application.GetOpenFilename
If DRAS2XXXX = False Then
MsgBox "No file selected. Macro terminated. Try again.", vbCritical, "Error"
Sheets("DRAS file").Select
Exit Sub
End If
Workbooks.OpenText (DRAS2XXXX)
DRASfilename = ActiveWorkbook.Name
thatfile = ActiveWorkbook.Name




Selection.TextToColumns Destination:=Range("A1"), 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, 2), Array(5, 2), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 2), Array(14, 1), Array(15 _
, 1)), TrailingMinusNumbers:=True








Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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