excel - 将 Excel 行输出到一系列文本文件

标签 excel notepad++ vba

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

这可能吗?

我的想法是,我有数百个这样的东西,我想让自己变得更容易。

如果 Excel 不适合此操作,有人可以建议替代方案吗? (Notepad++ 可能有一个可以提供帮助的功能?)

最佳答案

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 - 将 Excel 行输出到一系列文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7149539/

相关文章:

regex - 在 Notepad++ 中查找字符串的第 n 个实例

notepad++ - 如何在 Notepad++ 中的逗号后添加空格?

vba - EXCEL/VBA : converting boolean text to checks

java - Windows 7 Excel 的 Apache POI 替代品

用于对齐数据透视表的 VBA

notepad++ - 使用 notepad++ 查找并替换 URL

excel - VBA打开资源管理器并选择(而不是打开)选定的文件名

vba - Rows.Count 方法在 Excel VBA 中运行不佳(尽管我指定了获取行数的工作表,但它在错误的工作表中获取行数。)

c# - 使用 ADO 3.5 将数据从 Excel 导入 64 位应用程序

excel - 将多个值索引到单个单元格中