Const ForReading = 1 '设定打开文本方式为读取
Const ForWriting = 2 '设定打开文本方式为写入
Const ForAppending = 8 '设定打开文本方式为追加
Const InFile = "a.txt" '设定打开的文本
Dim StrLine,OutStr
Set objFSO = CreateObject("Scripting.FileSystemObject") '引用FSO对象,读写文件要用到的
Set objFile = objFSO.OpenTextFile(InFile, ForReading) '以读取方式打开InFile
Do Until objFile.AtEndOfStream
StrLine = objFile.ReadLine '读取一行
If Mid(StrLine,26,3) = "13-" Then
StrLine = Left(StrLine,25) & Mid(StrLine,29,27) & " " & Mid(StrLine,56)
ElseIf Mid(StrLine,26,2) = "13" Then
StrLine = Left(StrLine,25) & Mid(StrLine,28,28) & " " & Mid(StrLine,56)
End If
OutStr = OutStr & StrLine & vbCrLf
Loop
objFile.Close '关闭文件对象
OutFile = "sm" & FormatDate(Date) & ".txt"
Set objFile = objFSO.OpenTextFile(OutFile, ForWriting,True) '以写入方式打开OutFile
objFile.Write OutStr
objFile.Close '关闭文件对象
Set objFile = Nothing
Set objFSO = Nothing
Function FormatDate(tDate)
FormatDate = Right(Year(tDate),2) & AddZero(Month(tDate)) & AddZero(Day(tDate))
End Function
Function AddZero(sNum)
Addzero = Right("0" & sNum,2)
End Function |
|