Private Sub Command2_Click()
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim lsFileName As String
Dim llRow As Long
Dim llCol As Long
Dim lsTemp As String
Dim n() As String, ColNum As Integer
lsFileName = CdlTest.FileName
llRow = 0
Set xlBook = xlApp.Workbooks.Add()
Set xlsheet = xlBook.Worksheets(1)
Open lsFileName For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, lsTemp ' 读入一行数据并将其赋予某变量。
n = Split(lsTemp, " ")
Debug.Print lsTemp
llRow = llRow + 1
ColNum = 0
For llCol = 0 To UBound(n)
If Len(Trim(n(llCol))) Then
ColNum = ColNum + 1
xlsheet.Cells(llRow, ColNum) = n(llCol)
End If
Next
Loop
Close #1
xlBook.SaveAs lsFileName & ".xls"
xlBook.Close (True)
xlApp.Quit
Set xlApp = Nothing
MsgBox "文件转换已生成新文件" & m, vbInformation, "Display"
End Sub