【发布时间】:2013-11-06 13:17:24
【问题描述】:
我很乐意使用 VBA 将 Excel 工作表导入访问,并循环浏览给定文件夹以恢复其中的所有内容。但是,我想遍历一个文件夹并只导入文件的选择。有人可以帮忙吗?每个文件称为REPORT1 等并运行到REPORT67。我只想选择1-47。
下面的代码可以正常工作,但这只是从指定位置复制所有内容。
Sub Sample2()
Const cstrFolder As String = "F:\TCB_HR_KPI\Data View\"
Dim strFile As String
Dim i As Long
strFile = Dir(cstrFolder & "*.xls")
If Len(strFile) = 0 Then
MsgBox "No Files Found"
Else
Do While Len(strFile) > 0
Debug.Print cstrFolder & strFile
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strFile, cstrFolder & strFile, True
i = i + 1
strFile = Dir()
Loop
MsgBox i & " Files are imported"
End If
End Sub
【问题讨论】:
-
要求代码的问题必须表明对所解决问题的最低理解。包括尝试的解决方案、它们为什么不起作用以及预期的结果。另见:Stack Overflow question checklist
-
是的,我已经把我的原始代码放在上面了!!!!我现在需要帮助来调整它。无论如何感谢您的帮助。