2017-02-23 231 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 каждый раз. Любые идеи о том, как я могу изменить код, чтобы сделать это?

Спасибо,

Sub Import_CSV() «Измененный WillR - www.willr.info (декабрь 2004)

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" 

End Sub

Смежные вопросы