ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   update a txt file if dta is new (https://www.excelbanter.com/excel-programming/312474-update-txt-file-if-dta-new.html)

Mark

update a txt file if dta is new
 
In A5 I input a name on a daily basis, I am trying to write a macro that will
take the data in A5 and put it in a new line in a text file located at
c:/temp/list.txt
I will need to check first if the name is already there (there is only one
name per line) and if it is there not to add it again.
Can that be done.
Many thanks
Mark

Nikos Yannacopoulos[_5_]

update a txt file if dta is new
 
Mark,

Try this:

Sub Append_Line()
Dim vFile As String
Dim vLine As String
Dim vNewLine As String
Dim vFound As Boolean
vFile = "C:\Temp\List.txt"
vNewLine = Range("A5").Value
vFound = False
Open vFile For Input As #1
Do Until EOF(1)
Line Input #1, vLine
If vLine = vNewLine Then
Close #1
Exit Sub
End If
Loop
Close #1
Open vFile For Append As #1
Print #1, vNewLine
Close #1
End Sub

HTH,
Nikos

"mark" wrote in message
...
In A5 I input a name on a daily basis, I am trying to write a macro that

will
take the data in A5 and put it in a new line in a text file located at
c:/temp/list.txt
I will need to check first if the name is already there (there is only one
name per line) and if it is there not to add it again.
Can that be done.
Many thanks
Mark





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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com