同じフォルダ内の複数のファイルの最新バージョンを選択してExcelにインポートする方法がわかりません。例:フォルダ内のファイル複数のファイルの中から最近のファイルを選択して1枚のExcelシートにインポート
: Spanish.csv スペイン語(1) スペイン語を.csvファイルは、(2) English.csv 英語を.csvファイルには、(1)(多くはありFrench.csv を.csvファイルそのフォルダから、ここではより多くの言語やファイルが、私は簡単にするためにのみこれらを含むよ)
、私はこれらのファイルを選択します: スペイン語(2) 英語を.csvファイル(1).CSV French.csv
とそれをintにインポートする既存のワークシート1枚。
これまでのところ私が持っている:私は一緒にいくつかの部分をcobblingてるので
Sub GetFiles()
Dim MyPath As String
Dim Spanish As String
Dim English As String
Dim French As String
Dim LanguageFiles(2) As String
MyPath = "C:\example\"
'Make sure that the path ends in a backslash
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
Spanish = Dir(MyPath & "Spanish*.csv")
English = Dir(MyPath & "English*.csv")
French = Dir(MyPath & "French*.csv")
I WANT TO SOMEHOW GET THE MOST RECENT VERSION OF EACH AND PASS IT TO THE LANGUAGEFILES ARRAY AND IMPORT IT TO A SINGLE WORKSHEET.
LanguageFiles(0) = Spanish
LanguageFiles(1) = English
LanguageFiles(2) = French
For i = LBound(LanguageFiles) To UBound(LanguageFiles)
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & LanguageFiles(i), Destination:=Range("A" & Rows.Count).End(xlUp).Offset(1, 0))
.Name = "Sample"
.FieldNames = False
.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
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Next i
End Sub
このコードは実際には動作しませんし、私も正しい軌道に乗ってるかどうかは知りません。誰かが私を助けてくれますか?
FileSystemObjectオブジェクトを使用してを見て、datelastmodifed、および「*スペイン語*」のようなfl.nameは、日付を比較するので、もしあなたが、検索のように使用することができます.... –
ます。http:// stackoverflowの.com/questions/9205137/using-vbscript-to-find-latest-file-a-single-a-folder-a-single-folder –
http://www.4guysfromrolla.com/webtech/faq/FileSystemObject/faq5.shtml –