- 帖子
- 14
- 主題
- 3
- 精華
- 0
- 積分
- 17
- 點名
- 0
- 作業系統
- windows
- 軟體版本
- 2013
- 閱讀權限
- 10
- 註冊時間
- 2017-4-30
- 最後登錄
- 2019-11-23
|
不好意思版大
我文字文件檔的內容不定一樣@@
跑到這裡都會錯誤
裡面嘗試起來 第二樓的語法比較是理想的@@
但是要把第一行有空白格拿掉
再帶入EXCEL裡面
Option Explicit
Dim xPath As String
Sub Ex()
xPath = "d:\" 'ThisWorkbook.Path
Ex_修改最新文字檔
Workbooks.Open Latest_file(xPath) '匯入TXT到EXCEL
End Sub
Sub Ex修改文件檔案()
Dim F As Object, E, AR(), i As Integer, A As Variant, xFile As String
Dim My() As Integer
'Set F = CreateObject("Scripting.FileSystemObject").GetFolder(ThisWorkbook.Path).Files
Set F = CreateObject("Scripting.FileSystemObject").GetFolder("C:\Users\USER\Desktop\data").Files
'.Files ->這資料夾路徑中的所有的檔案
ReDim AR(1 To 2, 1 To F.Count)
For Each E In F
If E Like "*.mea" Then '檔案副檔名為txt
i = i + 1
AR(1, i) = E '陣列第一維 置入檔案名稱
AR(2, i) = CDbl(E.DateLastModified) '陣列第二維 置入存檔的日期時間
End If
Next
A = Application.WorksheetFunction.Index(AR, 2)
xFile = AR(Application.Match(Application.Max(A), A, 0), 1) '最新存檔的檔案名稱
Set F = CreateObject("Scripting.FileSystemObject").OpenTextFile(xFile, 1) '開啟文件檔,讀取模式
A = Split(F.ReadAll, vbLf) '讀取檔案內容
F.Close '關閉文件檔案
Set F = CreateObject("Scripting.FileSystemObject").CreateTextFile(xFile, True) '開啟文件檔,可覆蓋原文件檔模式
For i = 0 To UBound(A)
F.WriteLine (i)
Next
F.Close
End Sub
這是自己改的 可能不盡理想-..-
data.rar (57.5 KB)
|
|