VBA script to change some lines in text file.

Author Message
Rabidurbian

  • Total Posts : 4
  • Scores: 0
  • Reward points : 0
  • Joined: 12/29/2010
  • Status: offline
VBA script to change some lines in text file. Tuesday, January 04, 2011 1:36 AM (permalink)
0
Hi.
Do you know how to change new file size from list of files in text file ?
Thanks.
 
#1
    waitely

    • Total Posts : 4
    • Scores: 0
    • Reward points : 0
    • Joined: 1/31/2011
    • Status: offline
    Re:VBA script to change some lines in text file. Wednesday, March 09, 2011 8:31 PM (permalink)
    0
    If you want to edit a specific line in a file through VBScript you can use something like below. This reads the original file line by line and writes it out to a temporary file. If the original line meets the condition you want, make the changes required. At the end, close both files, delete the original and move the temp file.
    Const ForReading=1 
    Const ForWriting=2
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    folder = "C:\Program Files\Vendor\"
    filePath = folder & "file.txt"
    Set myFile = objFSO.OpenTextFile(filePath, ForReading, True)
    Set myTemp= objFSO.OpenTextFile(filePath & ".tmp", ForWriting, True)
    Do While Not myFile.AtEndofStream
     myLine = myFile.ReadLine
     If InStr(myLine, "Variable=") Then
      myLine = "Variable="&whatever
     End If

     myTemp.WriteLine myLine
    Loop
    myFile.Close
    myTemp.Close
    objFSO.DeleteFile(filePath)
    objFSO.MoveFile filePath&".tmp", filePath

    Web designers

     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9