Y
yjones
Guest
Hello -
I am having a real tough time trying to figure out this code. I am trying to import a massive amount of excel workbooks in a file into an access database. I am able to figure out how to import one workbook into the database using the transferspreadsheet method, but I want to be able to use some loop code so that the vb module in access goes through many spreadsheets in a particular file. I tried putting the following code together, but it gives me a 'compiled error - user defined type not defined' error. I'm not very familiar with vb, so i was hoping someone knew what i am doing wrong or if this is totally wrong, help me with the proper coding. Thank you very much in advance for helping!
Sub allfolderfiles()
Dim wb As workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Documents and Settings"
ChDir MyPath
TheFile = Dir("*.xls")
Do While TheFile <> ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
DoCmd.TransferSpreadsheet acImport, 8, "newml", "C:\Documents and Settings\*.xls", True, "range"
wb.Close
TheFile = Dir
Loop
End Sub
I am having a real tough time trying to figure out this code. I am trying to import a massive amount of excel workbooks in a file into an access database. I am able to figure out how to import one workbook into the database using the transferspreadsheet method, but I want to be able to use some loop code so that the vb module in access goes through many spreadsheets in a particular file. I tried putting the following code together, but it gives me a 'compiled error - user defined type not defined' error. I'm not very familiar with vb, so i was hoping someone knew what i am doing wrong or if this is totally wrong, help me with the proper coding. Thank you very much in advance for helping!
Sub allfolderfiles()
Dim wb As workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Documents and Settings"
ChDir MyPath
TheFile = Dir("*.xls")
Do While TheFile <> ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
DoCmd.TransferSpreadsheet acImport, 8, "newml", "C:\Documents and Settings\*.xls", True, "range"
wb.Close
TheFile = Dir
Loop
End Sub