How to output .csv rows to a series of seperate text files?
I saw this link, and the approach should be similar.. Outputting Excel rows to a series of text files
Can anyone help me know the steps and if i should use excel and suggest the steps, to achieve the above results as in the link or otherwise. Thanks in advance...
答案 0 :(得分:0)
假设您现在正在使用Excel ...
首先,就像我在其中一条评论中所说,你应该开始here来了解如何自己使用Visual Basic for Applications(VBA)。
在Excel中,最简单的方法是激活 Developer 选项卡以访问Visual Basic编辑器。
Code
部分下是 Visual Basic 。单击此按钮打开VBA编辑器。现在你可以制作VBA潜艇了。您可以将它们放在特定工作表,整个工作簿或PERSONAL.XLSB
中的模块中,这些模块允许任何启用了宏的Excel工作簿来运行它们。
您可能需要创建一个模块。如果是这样的话:
VBAProject (PERSONAL.XLSB)
。Insert
> Module
您现在可以将代码粘贴到模块中,并且有一个"宏"。
最简单的方法是
您还可以通过在同一Macros
菜单中点击选项... 来指定键盘快捷键。
现在,您可以从here复制并粘贴代码。稍作修改:
Sub Export_Files()
Dim sExportFolder, sFN
Dim rTitle As Range
Dim rContent 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 rTitle In oSh.UsedRange.Columns("A").Cells
Set rContent = rTitle.Offset(, 1) & ", " & rTitle.Offset(, 2) '<--This will put in your Column B and C value. You can delimit with whatever you desire; I used a comma and space.
'Add .txt to the article name as a file name
sFN = rTitle.Value & ".txt"
Set oTxt = oFS.OpenTextFile(sExportFolder & "\" & sFN, 2, True)
oTxt.Write rContent.Value
oTxt.Close
Next
End Sub