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
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