2014-02-23 77 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上的名稱的文件名的末尾?我怎麼做?

回答

相關問題