Import Excel files into Access whilst Looping

前端 未结 2 682
梦毁少年i
梦毁少年i 2021-01-25 17:07

I am comfortable with using VBA to import excel sheets into access, and to loop through a given folder to bring back everything in there. However, I want to loop through a fold

2条回答
  •  生来不讨喜
    2021-01-25 17:55

    I just replaced your code, "Do While Len(strFile) > 0" into "Do While Int(Mid(strFile, 7)) < 48", hope it helps.

    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 Int(Mid(strFile, 7)) < 48
            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
    

提交回复
热议问题