Hello lif,
This code adds the line "mesh autocreate" to the file designated by the variable OrigDoc. A new file, NewDoc, is opened and the line is added. The contents of OrigDoc are then read and copied into it. Lastly, the OrigDoc is deleted and NewDoc is renamed as OrigDoc. Be sure to change the DocName and DocPath variables to match your own.
This could also be done using API calls. However, I am not sure how you would envoke them outside of VBA.
Sub UpdateTextFile()
Dim F1 As Integer
Dim F2 As Integer
DocName = "Test File 1.txt"
DocPath = "C:\Documents and Settings\Jim\My Documents\"
OrigDoc = DocPath & DocName
NewDoc = DocPath & "NewDoc.txt"
NewLine = "mesh autocreate"
F1 = FreeFile
Open NewDoc For Output As F1
F2 = FreeFile
Print #F1, NewLine
Open OrigDoc For Input As F2
Do While Not EOF(F2)
Input #F2, Data
Print #F1, Data
Loop
Close #F2
Close #F1
Kill OrigDoc
Name NewDoc As OrigDoc
End Sub
Sincerely,
Leith Ross
Bookmarks