- 帖子
- 1572
- 主題
- 16
- 精華
- 2
- 積分
- 1521
- 點名
- 0
- 作業系統
- xp
- 軟體版本
- office 2003
- 閱讀權限
- 150
- 性別
- 男
- 註冊時間
- 2010-5-1
- 最後登錄
- 2016-1-13

|
3#
發表於 2011-5-27 14:07
| 只看該作者
- Sub yy()
- '引用Microsoft Scripting Runtime
- Application.ScreenUpdating = False
-
- Dim fso As Scripting.FileSystemObject
- Dim myTxt As Scripting.TextStream
- Dim myfile As String, myname$
- Dim i As Long, j%
-
- 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
- Sheets(myname).Cells(i, 1) = .ReadLine
-
- i = i + 1
- If i = 65530 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
複製代碼 沒文件可測試,你自己測試一下吧 |
|