我有大約900個CSV文件,所有這些文件都是從跟蹤軟件導出的。不幸的是,該軟件通過幀數據導入大約52行左右的彙總數據,這些數據有許多標題。自動將TXT文件導入到xls,並在excel或access中進行規範
我正在尋找一種方法來:
1)打開CSV文件
2)保存彙總數據與文件名 「Original_Summary」
3獨立的電子表格)使用原始文件名作爲工作表的新名稱,將逐幀數據(包含標題)保存到單獨的Excel文件中。
以前,我已經用〜124個文件手工完成了每個文件的剪切/粘貼操作,但由於文件數量太多了,我不確定手動操作是否是最好的選擇。
我有另一個腳本,我已經寫入,將這些excel文件作爲單獨的表格導入到Access中,但現在我需要一種方法將它們從CSV中轉移,並將頂部的所有額外摘要數據移入到單獨的文件。
有沒有辦法可以做到這一點?
謝謝!
Sub ImportManyTXTs_test()
Dim strFile As String
Dim foldername As String
Dim ws As Worksheet
strFile = Dir("C:\Users\Jared\Desktop\Processed\Text\*.txt")
Do While strFile <> vbNullString
Set ws = Sheets.Add
With ws.QueryTables.Add(Connection:= _
"TEXT;" & "C:\Users\Jared\Desktop\Processed\Text\" & strFile, Destination:=Range("$A$1"))
.Name = strFile
'.FieldNames = True
'.RowNumbers = False
'.FillAdjacentFormulas = False
'.PreserveFormatting = True
'.RefreshOnFileOpen = False
'.RefreshStyle = xlInsertDeleteCells
'.SavePassword = False
'.SaveData = True
'.AdjustColumnWidth = True
'.RefreshPeriod = 0
'.TextFilePromptOnRefresh = False
'.TextFilePlatform = 437
'.TextFileStartRow = 52
'.TextFileParseType = xlFixedWidth
'.TextFileTextQualifier = xlTextQualifierDoubleQuote
'.TextFileConsecutiveDelimiter = False
'.TextFileTabDelimiter = False
'.TextFileSemicolonDelimiter = False
'.TextFileCommaDelimiter = False
'.TextFileSpaceDelimiter = False
'.TextFileColumnDataTypes = Array(xlYMDFormat, 1, 1)
'.TextFileFixedColumnWidths = Array(22, 13, 13)
'.TextFileTrailingMinusNumbers = True
'.Refresh BackgroundQuery:=False
'.CommandType = 0
'.Name = "T15_070916_B"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 52
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
ActiveSheet.Name = strFile
strFile = Dir
Loop
End Sub
我已經試過這一點,這似乎並沒有上傳所有的我的文件,只有前99個左右,也不會將其導入到一個新的工作簿,而只能用一個新的工作表原來的擴展。出於某種原因,它也只能工作1次,然後才能刪除文件並重新開始。這很奇怪。
我還是一種新的編碼,所以任何幫助將不勝感激!
開始於手動錄製宏的操作?然後利用循環打開所有文件。 – PatricK
所以當我嘗試這個時,我遇到了程序的問題,直接將每個文件添加到工作簿作爲一個新的工作表,並與我不想要的文件名和擴展名。我想讓他們每個人都有他們自己的工作簿,工作表保留了原始文件名,我不知道該怎麼做。 – fishfishingfished