2014-02-23 78 views
0

我有一个Excel与文件名在B列A柱和在线内容文件Excel将单元格内容追加到文本文件的末尾。怎么样?

它看起来像这样:

file1|content1 
file2|content2 
file3|content3 

我也有与磁盘上创建txt文件的宏脚本VBA从A列,并与B列 以下内容的文件名的脚本:

Sub Export_Files() 
Dim sExportFolder, sFN 
Dim rArticleName As Range 
Dim rDisclaimer As Range 
Dim oSh As Worksheet 
Dim oFS As Object 
Dim oTxt As Object 

'sExportFolder = path to the folder you want to export to 
'oSh = The sheet where your data is stored 
sExportFolder = "C:\path\to\folder" 
Set oSh = Sheet1 

Set oFS = CreateObject("Scripting.Filesystemobject") 

For Each rArticleName In oSh.UsedRange.Columns("A").Cells 
    Set rDisclaimer = rArticleName.Offset(, 1) 

    'Add .txt to the article name as a file name 
    sFN = rArticleName.Value & ".txt" 
    Set oTxt = oFS.OpenTextFile(sExportFolder & "\" & sFN, 2, True) 
    oTxt.Write rDisclaimer.Value 
    oTxt.Close 
Next 
End Sub 

它的工作原理像它应该,但现在我想一些其他的数据附加到从现有文件的末尾excel工作表和当前脚本覆盖这些文件,并且它们只包含一行数据,这是最后出现在给定文件名的excel中的数据。

它看起来是这样的:

file1|content1 
file2|content2 
file3|content3 
file1|new_content4 
file2|new_content5 
file3|new_content6 

所以FILE1.TXT将有两条线,现在,作为一个例子:

content1 
new_content4 

是否有可能有从B列附加数据到列A上的名称的文件名的末尾?我怎么做?

回答

相关问题