Re: [問題] 多個txt檔可以另存到一個excel檔裡的多 …
※ 引述《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
→
08/18 23:31, , 1F
08/18 23:31, 1F
→
08/18 23:43, , 2F
08/18 23:43, 2F
→
08/18 23:43, , 3F
08/18 23:43, 3F
Office 近期熱門文章
PTT數位生活區 即時熱門文章