如何让这个脚本在读取后删除每一行文本,而不是仅仅进入下一行并仍然将其保留在文本文件中。
我可以做些什么来改变它?
Dim fso
Set objEmail = CreateObject("CDO.Message")
objEmail.From = """UPS"" <User@Example.com>"
objEmail.Subject = "This is a test"
Const ForReading=1
Set fso = CreateObject("Scripting.FileSystemObject")
Set dict = CreateObject("Scripting.Dictionary")
BodyText = fso.OpenTextFile("C:\Users\User\Desktop\UPS-Email.htm",ForReading).ReadAll
objEmail.HtmlBody = BodyText
'objEmail.AddAttachment "C:\Users\User\Desktop\test.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set dict = CreateObject("Scripting.Dictionary")
Set file = fso.OpenTextFile ("C:\Users\User\Desktop\e.txt", 1)
row = 0
Do Until file.AtEndOfStream
line = file.Readline
dict.Add row, line
row = row + 1
objEmail.To = line
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "127.0.0.1"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
Loop
答案 0 :(得分:1)
在您阅读文件时,您无法删除文件中的内容。您可以做的是在读完文件后截断文件:
Do Until file.AtEndOfStream
...
Loop
file.Close
fso.OpenTextFile("C:\Users\User\Desktop\e.txt", 2).Close