Results 1 to 4 of 4

Amending a text file

Threaded View

  1. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Amending a text file

    Just read the file as one giant string. Then run replace.

    It isn't clear what your exact requirement is... but something like below for single file read, replace string(s) and write back.
    Sub Demo()
    Dim iFile As String: iFile = "C:\Test\full-20190501.txt"
    Dim intFF As Integer: intFF = FreeFile()
    Dim textData As String
    
    Open iFile For Input As #intFF
    textData = Input$(LOF(intFF), #intFF)
    Close #intFF
    
    textData = Replace(textData, "Original String", "New String", , , vbBinaryCompare)
    Open iFile For Output As #intFF
    Print #intFF, textData
    Close #intFF
    End Sub
    EDIT: FYI - Tested on 34Mb log file with 250k+ rows. Took about 3~4 sec. Combine it with DIR() function to iterate over multiple files if needed.
    Last edited by CK76; 07-09-2019 at 02:12 PM.
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. SUMPRODUCT + TEXT (Month 27th) - Help amending this formula?
    By domgilberto in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 05-22-2014, 06:18 PM
  2. Help with VBA amending
    By sideshow1987 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-26-2011, 07:32 AM
  3. Excel 2007 : Amending data in a text file
    By Steve1973 in forum Excel General
    Replies: 1
    Last Post: 04-26-2011, 08:48 PM
  4. Changing/Amending Text String In Cell
    By Kumara_faith in forum Excel General
    Replies: 10
    Last Post: 02-19-2011, 10:44 AM
  5. looping, Open text file, copy text, close text file
    By jwilds1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-18-2009, 05:12 PM
  6. Replies: 0
    Last Post: 01-19-2006, 05:10 AM
  7. Amending a text file
    By DHallam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-19-2005, 07:19 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1