Sub a() Dim T, i%, k%, w, s$, L$ Set T = CreateObject("Scripting.FileSystemObject") L = InputBox("输入保存路径", "保存", "c:") For i = 2 To [IV1].End(1).Column Set w = T.CreateTextFile(L & "\" & i - 1 & ".txt", True) ReDim arr(1 To Len(Cells(1, i))) For k = 1 To Len(Cells(1, i)) s = Mid(Cells(1, i), k, 1) w.WriteLine (s) Next w.Close Next MsgBox "已全部生成!" End Sub
Sub a() Dim T, i%, w Set T = CreateObject("Scripting.FileSystemObject") For i = 2 To [IV1].End(1).Column Set w = T.CreateTextFile(ThisWorkbook.Path & "\" & i - 1 & ".txt", True) w.WriteLine (ActiveSheet.Cells(1, i).Value) w.Close Next MsgBox "已全部生成!" End Sub
点击文件名下载附件
菜鸟求一个vba,导出单元格内容为txt文件
Sub a() Dim T, i%, k%, w, s$ Set T = CreateObject("Scripting.FileSystemObject") For i = 2 To [IV1].End(1).Column Set w = T.CreateTextFile(ThisWorkbook.Path & "\" & i - 1 & ".txt", True) ReDim arr(1 To Len(Cells(1, i))) For k = 1 To Len(Cells(1, i)) s = Mid(Cells(1, i), k, 1) w.WriteLine (s) Next w.Close Next MsgBox "已全部生成!" End Sub
Sub a() Dim T, i%, k%, w, s$, L$ Set T = CreateObject("Scripting.FileSystemObject") L = InputBox("输入保存路径", "保存", "c:") For i = 2 To [IV1].End(1).Column Set w = T.CreateTextFile(L & "\" & i - 1 & ".txt", True) ReDim arr(1 To Len(Cells(1, i))) For k = 1 To Len(Cells(1, i)) s = Mid(Cells(1, i), k, 1) w.WriteLine (s) Next w.Close Next MsgBox "已全部生成!" End Sub