Outputting Excel rows to a series of text files

后端 未结 3 1109
小蘑菇
小蘑菇 2020-11-27 20:02

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 t

3条回答
  •  温柔的废话
    2020-11-27 20:22

    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
    

提交回复
热议问题