【发布时间】:2017-02-23 10:35:59
【问题描述】:
我正在尝试设置一个自动进程,该进程扫描特定网络文件夹以查找新的 CSV 文件,然后将数据附加到 Access 中的表中。
每天都会在文件夹中放置一个新的 CSV,它们都具有相同的命名约定 - ClosingPrice_ddmmyy,每个文件的日期部分都会更改。
设置此类流程最直接的方法是什么?
欢迎所有建议!
【问题讨论】:
我正在尝试设置一个自动进程,该进程扫描特定网络文件夹以查找新的 CSV 文件,然后将数据附加到 Access 中的表中。
每天都会在文件夹中放置一个新的 CSV,它们都具有相同的命名约定 - ClosingPrice_ddmmyy,每个文件的日期部分都会更改。
设置此类流程最直接的方法是什么?
欢迎所有建议!
【问题讨论】:
感谢您的回复,拉胡尔。 我在另一个论坛上找到了以下代码,它可以满足我的大部分需求。它从源文件夹中导入所有 CSV,并将它们添加到 Access 中的表中。但是,将来我只想添加添加到文件夹中的新 CSV,而不是每次都添加所有 CSV。关于如何更改代码以执行此操作的任何想法?
谢谢,
Sub Import_CSV()
'Modified from WillR - www.willr.info (December 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
【讨论】: