'Export MS Excel data to MS Access. How do I complete/adjust the code to allow different paths/folders for the spreadsheet and the database

Private Sub TransferDataToAsccess()
    Dim strXlPathFile As String, strXlFile As String, strXlPath As String
    Dim strAccessTable As String
    Dim blnHasFieldNames As Boolean

    'Change this next line to True if the first row in EXCEL worksheet has field names

    blnHasFieldNames = True

    'Replace C: \Documents\ with the real path to the folder that contains the EXCEL files 

    strXlPath = ThisWorkbook.Path & "\"

    'Replace tablename with the real name of the table into which the data are to be imported

    strAccessTable = "Tabell1"
    strXlFile = Dir(strXlPath & "*.xlsm")

    ' Transfer data from Excel to Access

    Do While Len(strXlFile) > 0

        strXlPathFile = strXlPath & strXlFile
        DoCmd.TransferSpreadsheet(acImport, acSpreadsheetTypeExcel9, strAccessTable, strXlPathFile, blnHasFieldNames)
        strXlFile = Dir()

    Loop

End Sub


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source