论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Excel教程
Tag:excel2000,excel2003,excel2007,函数,日期,时间,格式,技巧,表格,插入,,筛选,导入,导出,单元格,图表,打印,数据分析,排序,统计,公式,视频教程

Excel教程:Excel打开TXT文本文件,批量替换文本列的方法

文章类别:Excel | 发表日期:2012-5-26 11:50:15

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

目标:查找替换 正则表达式 通配符
视频教程列表
文章教程搜索
 
Excel推荐教程
Excel热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058