여러 CSV 파일을 하나의 큰 텍스트 파일로 결합했습니다. 이 텍스트 파일을 Excel로 가져 와서 텍스트 파일에 빈 행이 2 개있을 때마다 새 시트를 만들어야합니다.
이를 수행 할 수있는 매크로가 있습니까?
Example.TXT 파일 :
"Date","Country","Price",
"12/01/12","US","$4.99",
"12/02/12","US","$4.99",
"Date","Country","Price",
"12/01/13","US","$4.99",
"12/02/13","US","$4.99",
"Date","Country","Price",
"12/01/14","US","$4.99",
"12/02/14","US","$4.99",
좋아요, 아무도 도와주지 않았습니다. 그래서 큰 텍스트 파일을 삭제하고 모든 원본 csv를 가져 오는 매크로를 만들었습니다.
Sub LoadAllFilesPerSheet()
Dim idx As Integer
Dim fpath As String
Dim fname As String
idx = 0
fpath = "c:\foobar\"
fname = Dir(fpath & "*.csv")
While (Len(fname) > 0)
idx = idx + 1
Sheets("Sheet" & idx).Select
Sheets.Add After:=ActiveSheet
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" _
& fpath & fname, Destination:=Range("A1"))
.Name = "a" & idx
.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 = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = ""
.TextFileColumnDataTypes = Array(1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
fname = Dir
End With
Wend
End Sub
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다