2017-02-23 5 views
-1

특정 네트워크 폴더에서 새 CSV 파일을 검색 한 다음 Access의 테이블에 데이터를 추가하는 자동 프로세스를 설정하려고합니다.CSV 파일을 Access 테이블에 자동으로 가져 오기

새 CSV는 매일 폴더에 저장되며 이름 지정 규칙은 모두 ClosingPrice_ddmmyy이며 모든 파일에서 날짜 부분이 변경됩니다.

이러한 프로세스를 설정하는 가장 직접적인 방법은 무엇입니까?

모든 제안을 환영합니다!

+0

사용'docmd.transferspreadsheet' 방법 행사. 이 링크 [Link1] (https://access-programmers.co.uk/forums/showthread.php?t=224155), [Link2] (http://access-excel.tips/access-vba-cocmd- transferspreadsheet /) – harun24hr

답변

0

답장을 보내 주셔서 감사합니다. 내가 원했던 대부분의 다른 포럼에서 다음 코드를 발견했습니다. 원본 폴더에서 모든 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" 

최종 하위

관련 문제