Import Excel files into Access whilst Looping

前端 未结 2 681
梦毁少年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:48

    I would do: Dir$() DoWhile Val(Mid(filename, 7, 2))<48 Import the file Dir$() Loop

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题