私は初心者であり、あなたの助けと忍耐は非常に高く評価されます。多くのtksは事前に。私は、アクセスのdbaseテーブルにファイル名を取得する正しい構文/コードが必要です。以下はコードと出力です。出力は8列、最初の7列は数字、8列はファイル名が必要な場所です。コードはディレクトリに移動し、すべてのcsvファイルがあるかどうかを確認してから、csvデータをアクセス用dbaseテーブルにインポートします。列 'com'にcsvファイル名を設定する必要があります。現時点では文字列が入力されています。アクセステーブルへのファイル名
Sub Import_multiple_csv_files()
Const strPath As String = "C:\text1\" 'Directory Path
Dim strFile As String 'Filename
Dim strFileList() As String 'File Array
Dim intFile As Integer 'File Number
Dim SQL As String
'Loop through the folder & build file list
strFile = Dir(strPath & "*.csv")
While strFile <> ""
'add files to the list
intFile = intFile + 1
ReDim Preserve strFileList(1 To intFile)
strFileList(intFile) = strFile
strFile = Dir()
Wend
'see if any files were found
If intFile = 0 Then
MsgBox "No files found"
Exit Sub
End If
'cycle through the list of files & import to Access
'creating a new table called MyTable
SQL = " UPDATE Test SET Com = ""'strFile'"" WHERE Com IS NULL OR Com=''"
For intFile = 1 To UBound(strFileList)
DoCmd.TransferText acImportDelimi, , _
"Test", strPath & strFileList(intFile)
'DoCmd.RunSQL SQL
CurrentDb.Execute SQL
出力は、あなたが新しいものを上げるよりも、あなたの元の質問を編集したほうが良いでしょう
F1 F2 F3 F4 F5 F6 F7 com
20111128 2.6922 2.6922 2.6922 2.6922 3340 17696 'strFile'
20111129 2.7229 2.7229 2.7229 2.7229 5010 18141 'strFile'
20111130 2.7401 2.7401 2.7401 2.7401 3641 18723 'strFile'
20111201 2.7376 2.7376 2.7376 2.7376 8087 19321 'strFile'
20111202 2.7784 2.7784 2.7784 2.7784 0 0 'strFile'
20111128 2.6727 2.6727 2.6727 2.6727 3889 26111 'strFile'
20111129 2.7039 2.7039 2.7039 2.7039 4562 26647 'strFile'
20111130 2.722 2.722 2.722 2.722 3043 27099 'strFile'
20111201 2.7218 2.7218 2.7218 2.7218 9180 27037 'strFile'
20111202 2.7623 2.7623 2.7623 2.7623 0 0 'strFile'
こんにちは、ご意見ありがとうございます。私は上記のスクリプトを試しましたが、現在comの出力は2つの引用符です ''?私は間違って何をしていますか?どうもありがとう。 –
おそらくそれはそれぞれの側に1つの単一引用符です。 VBAを実行してからしばらく経っており、現在のコンピュータにAccessがインストールされていないため、テストできません。 – Simon
あなたの助けをたくさんありがとう –