想用VBA打开一文本文件,修改其中的数据内容,将所有形如111222的数据替换成AAABBB。请坛中高手帮帮忙,谢谢了。

解决方案 »

  1.   

    这个的操作和在VB中一样啊dim fninput as long
    dim fnoutput as long
    dim strLine as stringfninput=freefile
    open infile for input as fninput
    fnoutput=freefile
    open outfile for output as fnoutputdo while not eof(fninput)
        line input #fninput,strLine
        '按照需要处理你的内容
         print #fnoutput, strLine
    loopclose #fninput
    close #fnoutput
      

  2.   

    Dim strA As String
    Dim strTemp As String
    strA = '11112222'
    strTemp = strA
    Dim strB As String
    strTemp = Replace(strTemp, '1', 'A')
    strTemp = Replace(strTemp, '2', 'B')'VB.Net中使用String类的Replace方法
    'strTemp.Replace('1', 'A')
    'strTemp.Replace('2', 'B')strB = strTemp
      

  3.   

        Workbooks.OpenText Filename:= _
            "C:\Documents and Settings\Administrator\桌面\新建文件夹 (9)\g2.txt", Origin:=936, _
            StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
            ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
            , Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
            TrailingMinusNumbers:=True
        Cells.Replace What:="111222", Replacement:="AAABBB", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        ActiveWorkbook.SaveAs Filename:= _
            "C:\Documents and Settings\Administrator\桌面\新建文件夹 (9)\g2.txt", FileFormat:= _
            xlText, CreateBackup:=False
      

  4.   

    录制宏不行吧??他是说文本文件中的替换呀... 5楼的貌似可以
    LZ可以这样,用excel打开你的文本文件,再录制宏进行替换,最后保存成txt文件
    也能实现你的效果.....