1、保存为文本文件
Public Sub Save_Txt(ByVal txt1, ByVal file_name)
Dim i As Long
Open "d:\text.txt" For Output As #1
Print #1, txt1'你报保存的每行的文本,可以用循环控制
Close #1
End Sub
2、保存为execl
Public Sub Save_Execl(ByVal msf1 As MSFlexGrid)
Dim i As Integer, j As Integer
Dim NewXls As Excel.Application
Dim NewBook As Excel.Workbook
Dim NewSheet As Excel.Worksheet
Dim objRange As Object
Dim CellsData1() As String
Dim nRows As Long, nColumns As Long
Set NewXls = CreateObject("Excel.Application") '创建excel应用程序,打开excel2000
NewXls.SheetsInNewWorkbook = 1
Set NewBook = NewXls.Workbooks.Add '创建工作簿
Set NewSheet = NewBook.Worksheets(1) '创建工作表
NewXls.DisplayAlerts = False '
'也可以逐行赋值
nRows = '行
nColumns =' 列
ReDim CellsData1(0 To nRows, 0 To nColumns)
For i = 0 To nRows - 1
For j = 0 To nColumns - 1
CellsData1(i, j) = '行列的值
Next
Next
Set NewSheet = NewBook.Worksheets(1) '创建工作表
'导出到Excel中
Set objRange = NewSheet.Range(NewSheet.Cells(1, 1), NewSheet.Cells(nRows, nColumns))'cell前加上sheet或xlapp否则二次打开报错
objRange.Value = CellsData1
NewXls.Visible = True‘【newxls.saveas filename】
DoEvents
Set NewBook = Nothing
Set NewXls = Nothing
End Sub