Excel教程:Excel打开TXT文本文件,批量替换文本列的方法
Sub 读写txt()
Dim j As Integer
Dim i&, s() As String
For j = 1 To 10
Open ThisWorkbook.Path & "\" & Range("A" & j) & ".txt" For Input As #1
s = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
Close #1
Open ThisWorkbook.Path & "\" & Range("A" & j) & ".txt" For Output As #1
For i = 0 To UBound(s)
If InStr(s(i), " Print #1, s(i)
Next
Close #1
Next j
End Sub
=""&""""
Chr(34)
Chr(10)是不行的,因为回车符是双字节字符,用这个Chr(13) & Chr(10)
chr(13)和chr(10)在win系统下都是一样效果,
而在linux系统中,有效的换行只能为为chr(10),即/n
为了统一格式和兼容,所有文本换行一率采用\r\n,即chr(13)+chr(10)的组合来确定
Sub 读写htm()
Dim j As Integer
Dim i&, s() As String
For j = 1 To 10
Open ThisWorkbook.Path & "\" & Range("A" & j) & ".htm" For Input As #1
s = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
Close #1
Open ThisWorkbook.Path & "\" & Range("A" & j) & ".htm" For Output As #1
For i = 0 To UBound(s)
'Debug.Print " If InStr(s(i), " Print #1, s(i)
Next
Close #1
Next j
End Sub
Sub 插入时间()
Dim j As Integer
Dim i&, s() As String
For j = 2 To 40
Debug.Print ThisWorkbook.Path & "\ppt\ppt.files\" & Range("P" & j) & ".htm"
Open ThisWorkbook.Path & "\ppt\ppt.files\" & Range("P" & j) & ".htm" For Input As #1
s = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
Close #1
Open ThisWorkbook.Path & "\ppt\ppt.files\" & Range("P" & j) & ".htm" For Output As #1
For i = 0 To UBound(s)
'Debug.Print " If InStr(s(i), " s(i) = Replace(s(i), " ElseIf InStr(s(i), "--><![endif]>") Then
s(i) = Replace(s(i), "--><![endif]>", "--><![endif]>" & Range("R" & j))
Else
Debug.Print Range("I" & j)
End If
Print #1, s(i)
Next
Close #1
Next j
End Sub
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |