답장을 보내 주셔서 감사합니다. 내가 원했던 대부분의 다른 포럼에서 다음 코드를 발견했습니다. 원본 폴더에서 모든 CSV를 가져와 Access 내의 테이블에 추가합니다. 그러나 앞으로는 모든 CSV가 아닌 폴더에 추가되는 새로운 CSV를 추가하고 싶습니다. 이 작업을 수행하기 위해 코드를 어떻게 바꿀 수 있습니까?
감사합니다,
하위 Import_CSV() 는 'WillR에서 수정 - 타이머 www.willr.info을 (2004 12월)
이
Const strPath As String = "C:\ImportFolder\" 'Directory Path
Dim strFile As String 'Filename
Dim strFileList() As String 'File Array
Dim intFile As Integer 'File Number
'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
For intFile = 1 To UBound(strFileList)
DoCmd.TransferText acImportDelimi, ImportSpec, _
"Raw Data", strPath & strFileList(intFile), -1
'Check out the TransferSpreadsheet options in the Access
'Visual Basic Help file for a full description & list of
'optional settings
Next
MsgBox UBound(strFileList) & " Files were Imported"
최종 하위
사용'docmd.transferspreadsheet' 방법 행사. 이 링크 [Link1] (https://access-programmers.co.uk/forums/showthread.php?t=224155), [Link2] (http://access-excel.tips/access-vba-cocmd- transferspreadsheet /) – harun24hr