yvll 发表于 2015-2-2 16:21
您好,能否帮助我将导出的文本文件内的数字由横排改为1列竖排,每个数字后面不要有空格。例如
01
02
Sub t()
Dim arr, i&, j&, s$, m%
Dim myPath$, fs, f
myPath = ThisWorkbook.Path & "\"
arr = Range("X2:AE33")
Set fs = CreateObject("Scripting.FileSystemObject")
For i = 1 To UBound(arr)
If fs.FolderExists(myPath & i) Then '文件夹是否存在
fs.DeleteFolder (myPath & i) '删除文件夹
End If
Next
For i = 1 To UBound(arr)
m = 0
For j = 1 To UBound(arr, 2)
If Not IsError(arr(i, j)) Then '判断是否为错误值
s = Replace(Trim(arr(i, j)), " ", vbCrLf)
If IsNumeric(Left(s, 1)) And Len(s) > 0 Then '判断是否为数值且不为空
m = m + 1 '计算
If m = 1 Then fs.CreateFolder (myPath & i) '创建文件夹
Set f = fs.CreateTextfile(myPath & i & "\" & m & ".txt", True) '创建文本
f.write s '写入
f.Close '关闭
End If
End If
Next
Next
MsgBox "完成!!"
End Sub
|