View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default rows.count property returns 2 even though only 1 row was imported by querytables.add

This is typical when the process writing the data to the text file doesn't
deliberately exclude the last carriage-return/linefeed. So importing as
you've done will include a blank record causing the record count to inflate
by 1!


Garry,

Thanks but the inflation-by-one only occurs if the file has just one line,
with or without the CR/LF (as created by venerable Notepad); with 2 or more
lines, Rows.count returns the expected result.

Strangely, for a zero-length file it throws error 7 "out of memory" when zero
is surely the expected result.


Actually, Notepad itself doesn't add anything past your last line; - cr/lf's
are created by the user of Notepad via the keyboard or by pasting other text
containing a trailing 'newline'. When copying, any space after the last text
character is the culprit since that space is likely the non-printing cr/lf!

Writing to a plain text file via code (in most programming language's file I/O
processes) typically includes a trailing cr/lf. To avoid this happening must be
deliberately coded for.

Also, using Query is ominous at best; - via code you'd be better off using VBA
file I/O (IMO)!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion