您好,欢迎来到Office教程网
您的位置: 主页 > Excel教程 > Excel基础 >

用Excel批量替换文本列

时间:2012-05-06 来源:office.sc115.com阅读:

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

    office教程 - office2007免费版下载 - word教程 - 网站地图