作者bulldog ()
看板Office
標題Re: [問題] 多個txt檔可以另存到一個excel檔裡的多 …
時間Wed Aug 18 23:31:11 2010
※ 引述《gil9 (GiL)》之銘言:
簡單寫一下
有問題大家在討論吧
Option Explicit
Sub 讀取文字檔()
Dim MyDir, txtFile, StrLine As String
Dim I As Integer
Dim J As Long
Dim Data As Variant
MyDir = Dir("文字檔路徑\*.txt")
Do While MyDir <> ""
J = 1
txtFile = "文字檔路徑\" & MyDir
Open txtFile For Input As #1
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
Sheets(Worksheets.Count).Name = Left(MyDir, Len(MyDir) - 4)
Do While Not EOF(1)
Line Input #1, StrLine
Data = Split(StrLine, ",")
For I = 0 To UBound(Data)
Sheets(Worksheets.Count).Cells(J, I + 1) = Data(I)
Next
J = J + 1
Loop
Close #1
MyDir = Dir()
Loop
End Sub
: (若是和其他不同軟體互動之問題 請記得一併填寫)
: 軟體:Excel
: 版本:2003
: 我有100個txt檔需要匯整成100個sheet(一個檔案)
: 只能一個一個txt檔不停地匯入嗎?
: 有沒有其他更快捷的方法呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.70.221.101
→ bulldog:順帶一提 這個程式會把該路徑底下的文字檔都讀取近來... 08/18 23:31
→ bulldog:還有我測試的文字檔是逗號分隔 一般的還是直接用workbook 08/18 23:43
→ bulldog:open Cells.copy paste吧 08/18 23:43