Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
file append & opposite #2
Group,
I've written some VBA code to add some data to a file using something similar to: open "c:\temp\junk.txt" for append as #1 I now wish to write some code to remove this data. Example: The file starts out as 23,847 bytes and my macro makes it 23,857 bytes. What code would move the EOF up ten bytes restoring the file as it originally was? Thanks in advance, Christmas |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
file append & opposite #2
One way:
Option Explicit Sub testme() Dim myFileName As String Dim myContents As String ' Dim FSO As Scripting.FileSystemObject ' Dim myFile As Scripting.TextStream ' Set FSO = New Scripting.FileSystemObject Dim FSO As Object Dim myFile As Object Set FSO = CreateObject("Scripting.FileSystemObject") myFileName = "C:\my documents\excel\test.txt" If FSO.fileexists(myFileName) = False Then MsgBox "quitting!" Exit Sub End If Set myFile = FSO.OpenTextFile(myFileName, 1, False) myContents = myFile.ReadAll myFile.Close myContents = Left(myContents, Len(myContents) - 10) Set myFile = FSO.CreateTextFile(myFileName, True) myFile.Write myContents myFile.Close End Sub Christmas May wrote: Group, I've written some VBA code to add some data to a file using something similar to: open "c:\temp\junk.txt" for append as #1 I now wish to write some code to remove this data. Example: The file starts out as 23,847 bytes and my macro makes it 23,857 bytes. What code would move the EOF up ten bytes restoring the file as it originally was? Thanks in advance, Christmas -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Append text file | Excel Discussion (Misc queries) | |||
File Append & Opposite | Excel Programming | |||
append file on e-mail | Excel Programming | |||
append file on e-mail | Excel Discussion (Misc queries) | |||
File Append Row by Cell value | Excel Programming |