Av8tordude
Well-known Member
- Joined
- Oct 13, 2007
- Messages
- 1,075
- Office Version
- 2019
- Platform
- Windows
I have this code in my workbook open and workbook close events. When the workbook opens, the code is to edit the second entry (which it does exactly what it is suppose to do), however, when I close the workbook, instead of editing the second entry, it enters duplicate entries. The code is only to edit the second entry of the text file.
The code is to only edit the second entry only, not create duplicates. Can someone help fix this problem.
43678.3604398148
43691.4231597222
The code is to only edit the second entry only, not create duplicates. Can someone help fix this problem.
43678.3604398148
43691.4231597222
Code:
Set fs = CreateObject("Scripting.FileSystemObject")
f = fs.OpenTextFile(OPath & TmEvnt).readall
pTime = Trim(Split(f, vbCrLf)(0))
CurrentTime = Format(Now, "#0.#########0")
Open OPath & TmEvnt For Input As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL]
Do While Not EOF(1)
Line Input [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , s
n = n + 1
If n = 2 Then s = CurrentTime
ss = ss & s & vbNewLine
Loop
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL]
Open OPath & TmEvnt For Output As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL]
Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , ss
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL]