Strange problem when reading from a text file

Thomas B

New Member
Joined
Jul 10, 2003
Messages
36
Dear all,
I have a macro that reads from a text file, but it skips trailing '1'!
Have tried a lot with the original macro, and boiled it down to the very basic here. Tried a lot with the format specifiers, but no luck.
When playing around with the context of test.txt, it seems like VBA is treating '1' as a seperator

Any clues?

Thanks Thomas B.

text file : test.txt

41
42


macro
Sub ReadPrjFileNew()
FileName = "TEST.txt"
CompleteFileName = "TEXT;" & FileName

' Start with clearing the whole lot
Cells.Select
Selection.ClearContents
Selection.FormatConditions.Delete
Selection.ColumnWidth = 10
Selection.Font.FontStyle = "normal"
Selection.Interior.ColorIndex = xlNone

With ActiveSheet.QueryTables.Add(Connection:= _
CompleteFileName, Destination:=Range("A1") _
)
.Name = FileName
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
'.TextFileTextQualifier = xlTextQualifierNone
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileOtherDelimiter = xlTextQualifierDoubleQuote
.TextFileColumnDataTypes = Array(xlTextFormat)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,230
Office Version
  1. 365
Platform
  1. Windows
Remove this line:
Code:
.TextFileOtherDelimiter = xlTextQualifierDoubleQuote

xlTextQualifierDoubleQuote is a constant that has the value 1.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,270
Messages
5,600,638
Members
414,398
Latest member
dhune

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
Top