本文介绍了将 Excel 行输出到一系列文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Excel 中,我在 A 列中有一个文章名称列表,在 B 列中有一个免责声明.现在对于 A 列中的每篇文章,我想创建一个文本文件,其中 A 是文件的标题和B,免责声明,是文件的内容.
Inside Excel, I have a list of article names in column A, and a disclaimer inside column B. Now for each article in column A, I would like to create a text file, were A is the title of the file and B, the disclaimer, is the contents of the file.
这可能吗?
这个想法是我有几百个这样的,我想让自己更容易.
The idea is that I have several hundred of these, and I would like to make this easier on myself.
如果 Excel 不适合于此,有人可以提出替代方案吗?(可能 Notepad++ 有一个可以提供帮助的功能?)
If Excel is not ideal for this, can anyone suggest an alternative? (possibly Notepad++ has a feature that can help?)
推荐答案
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:Disclaimers"
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 行输出到一系列文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!