Sub 自動分頁導入()
Application.ScreenUpdating = False
Dim fso As Scripting.FileSystemObject
Dim mytxt As Scripting.TextStream
Dim myfile As String, myname$
Dim i As Long, j%
'****
Dim a() As String
Dim k As Long
'****
ActiveSheet.Cells.Clear
myfile = Application.GetOpenFilename("text files(*.txt),*.txt", , "請選擇文本文件")
Set fso = New Scripting.FileSystemObject
Set mytxt = fso.OpenTextFile(FileName:=myfile, IOMode:=ForReading)
With mytxt
i = 1: j = 1: myname = "sheet" & j
Do Until .AtEndOfStream
'********
a = Split(.ReadLine, ",")
For k = 0 To UBound(a)
Sheets(myname).Cells(i, k + 1) = a(k)
Next k
Erase a
'Sheets(myname).Cells(i, 1) = .ReadLine
'**********
i = i + 1
If i = 50000 Then
j = j + 1
If j > 3 Then
Sheets.Add after:=Sheets(myname)
End If
myname = "sheet" & j
i = 1
End If
Loop
.Close
End With
End Sub
网上搜的 |