Sub 使用示例()
'' Application.ScreenUpdating = False
' Application.DisplayAlerts = False
arr = Range("A1").CurrentRegion
WenjianM = "生成的文件"
Call 数组生成文件(WenjianM, arr)
' Application.DisplayAlerts = True
' Application.ScreenUpdating = True
End Sub
Function 数组生成文件(wm, arr)
On Error Resume Next
Dim fso As Object
Set fso = VBA.CreateObject("Scripting.FileSystemObject")
' fso.DeleteFile (ThisWorkbook.Path & "\" & wm & ".TxT")
'复制数据
Dim i As Integer
Dim data As String
For Each ar In arr
If ar = "" Then Exit For
data = data & ar & vbCrLf
Next
'创建并保存txt文件
Dim fileName As String
fileName = ThisWorkbook.Path & "\" & wm & ".txt"
Dim fileNum As Integer
fileNum = FreeFile()
Open fileName For Output As fileNum
Print #fileNum, data
Close fileNum
End Function