本文介绍了将Excel行输出到一系列文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Excel中,我有列A列中的文章名称和列B中的免责声明。现在对于列A中的每篇文章,我想创建一个文本文件,A是文件的标题, B,免责声明,是该文件的内容。



这是可能吗?



想法是我有几百个,我想让自己更容易。



如果Excel不适合这个,有人可以建议一个替代方案吗? (可能的记事本++有一个功能可以帮助?)

解决方案
  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 =要导出到
'的文件夹的路径oSh =存储数据的工作表
sExportFolder =C:\Disclaimers
设置oSh = Sheet1

设置oFS = CreateObject(Scripting.Filesystemobject)

对于每个rArticleName在oSh.UsedRange.Columns(A)。单元格
设置rDisclaimer = rArticleName.Offset(,1)

'将.txt作为文件名添加到文章名称
sFN = rArticleName.Value& .txt
设置oTxt = oFS.OpenTextFile(sExportFolder&\& sFN,2,True)
oTxt.Write rDisclaimer.Value
oTxt.Close
Next
End Sub


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.

Is this possible?

The idea is that I have several hundred of these, and I would like to make this easier on myself.

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行输出到一系列文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 13:19
查看更多