Option ExplicitPrivate Sub Command1_Click() Dim M As Long Dim N As Long Dim OutStr As String Dim A() As String
'............................
For M = 0 To UBound(A, 1) For N = 0 To UBound(A, 2) OutStr = A(M, N) & OutStr & Chr(vbKeyTab) Next OutStr = OutStr & Chr(13) Next WritTextFile "C:\DEMO.TXT", OutStr End Sub' '写TEXT文件 '函数:WritTextFile '参数:FileName 目标文件名.WritStr 写到目标的字符串. '返回值:成功 返回文件内容.失败 返回"" '注:如果同名,目标字符串将覆盖原文件内容. Public Function WritTextFile(Filename As String, WritStr As String) As Boolean '/保存文件 Dim FileID As Long, ConTents As String Dim A As Long, B As Long
On Error Resume Next
FileID = FreeFile Open Filename For Output As #FileID Print #FileID, WritStr Close #FileID WritTextFile = (Err.Number = 0) Err.Clear End Function
Dim M As Long
Dim N As Long
Dim OutStr As String
Dim A() As String
'............................
For M = 0 To UBound(A, 1)
For N = 0 To UBound(A, 2)
OutStr = A(M, N) & OutStr & Chr(vbKeyTab)
Next
OutStr = OutStr & Chr(13)
Next
WritTextFile "C:\DEMO.TXT", OutStr
End Sub'
'写TEXT文件
'函数:WritTextFile
'参数:FileName 目标文件名.WritStr 写到目标的字符串.
'返回值:成功 返回文件内容.失败 返回""
'注:如果同名,目标字符串将覆盖原文件内容.
Public Function WritTextFile(Filename As String, WritStr As String) As Boolean
'/保存文件
Dim FileID As Long, ConTents As String
Dim A As Long, B As Long
On Error Resume Next
FileID = FreeFile
Open Filename For Output As #FileID
Print #FileID, WritStr
Close #FileID
WritTextFile = (Err.Number = 0)
Err.Clear
End Function