- 帖子
- 4901
- 主題
- 44
- 精華
- 24
- 積分
- 4916
- 點名
- 120
- 作業系統
- Windows 7
- 軟體版本
- Office 20xx
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台北
- 註冊時間
- 2010-4-30
- 最後登錄
- 2025-5-18
               
|
4#
發表於 2013-8-12 08:50
| 只看該作者
回復 3# metrostar - Sub test()
- Dim fs, ar, fn$, br(1 To 10000, 1 To 7), t
- Dim c, i&, j&, r&, ph$
- ph = ThisWorkbook.Path & "\" '檔案目錄
- c = Array(0, 0, 1, 2, 3, 4, 5, 7)
- fs = Application.GetOpenFilename("Text Files (*.txt), *.txt", , , , True)
- If Not IsArray(fs) Then MsgBox "沒有選取檔案 !!!": Exit Sub
- With CreateObject("vbscript.regexp")
- .Global = True
- .Pattern = " +(?!$)"
- s = LBound(fs)
- While s <= UBound(fs)
- Open fs(s) For Input As #1
- ar = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
- Reset
- For i = 4 To UBound(ar) - 1
- r = r + 1
- ar(i) = .Replace(ar(i), "|")
- t = Split(ar(i), "|")
- For j = 1 To UBound(c)
- br(r, j) = t(c(j))
- Next
- br(r, 2) = Mid(Replace(fs(s), ph, ""), 6, 8)
- Next
- Close #1
- s = s + 1
- Wend
- End With
- With Sheets("Sheet2")
- .Range("2:" & Rows.Count).ClearContents
- .Range("a:a").NumberFormatLocal = "@"
- If r > 0 Then .[a2].Resize(r, UBound(br, 2)) = br
- End With
- End Sub
複製代碼 |
|