Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Delete a line in a text file

I have created a text file using the Open Statement. How do I delete a specific line say line 3 using VBA codes? Any help is very much appreciated. Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Delete a line in a text file

You need to read the existing file and write out the required lines to a new file, then delete the existing file and rename the new one to the same name

If the lines that you want to omit can be dropped with SQL, you can use the ODBC text driver & ADO to select the lines you want. Then use the GetString method to write the lines to a new file. Amount to the same thing!
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default Delete a line in a text file

"AA2e72E" wrote ...

If the lines that you want to omit can be dropped with
SQL, you can use the ODBC text driver & ADO to select
the lines you want.


I've never been able to delete a row / line in a text file (nor
Excel!) using SQL, either using the ODBC text driver or the OLE DB
Provider for Jet e.g.

DELETE
FROM Patient.txt
WHERE Patient_ID = 2

returns an error. If you have been able to do this I'd be interested
to learn the details.

What I am able to do (OLEDB and ODBC) is to select the required rows
into a new text file e.g.

SELECT *
INTO MyNewFile.txt
FROM Patient.txt
WHERE Patient_ID < 2

Perhaps this is what you were suggesting? (I don't get what you mean
by 'GetString'.)

The above relies on having a key column. Of course, SQL is set based
rather than procedural and therefore has no concept of 'row number'.
There is no way to say DELETE ROW 3 in SQL (barring a kludge!)

Jamie.

--
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Delete a line in a text file

Thanks AA2e72E for your suggestion.

"AA2e72E" wrote:

You need to read the existing file and write out the required lines to a new file, then delete the existing file and rename the new one to the same name.

If the lines that you want to omit can be dropped with SQL, you can use the ODBC text driver & ADO to select the lines you want. Then use the GetString method to write the lines to a new file. Amount to the same thing!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Challenge - Excel Line Feed Character CHR(10) - How to Delete and keep the text formatting without going ro single line in a cell ? No Name Excel Worksheet Functions 7 October 7th 09 11:10 AM
How do I delete a few words from a line of text? lauras03 Excel Worksheet Functions 3 February 16th 07 06:20 PM
Delete a line in text file Francis Ang[_2_] Excel Programming 2 June 11th 04 04:26 AM
End of file marker from Text File - Delete? 43fan Excel Programming 0 April 29th 04 06:06 PM


All times are GMT +1. The time now is 04:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"