
Originally Posted by
data123
The spreadsheet have the same name. I'm currently using a transfer spreadsheet marco that loads the spreadsheets, it only takes about 1 min for it to run per spreadsheet. But I have sometimes about 20 to 30 a day to do this for.
If the workbooks are identical in structure, then what I would do is this:
1) As the workbooks come in each week (presumably by email), save each workbook (modifying the name so as to make it unique to the folder) into a particular folder
2) Use a VBA sub that will loop through that folder, and iteratively run DoCmd.TransferSpreadsheet to import the data from those workbooks
Here is a starting point for you, based on something I did in the recent past:
Code:
Option Compare Database
Option Explicit
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
"SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
"SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Sub ImportFromTrackers()
' sub will prompt user for a directory, then grab tracker data from all Excel
' workbooks in that directory (but not subdirectories!)
Dim GetDir As String
Dim fso As Object
Dim Fld As Object
Dim Fil As Object
GetDir = GetDirectory("Choose folder with tracking workbooks")
If GetDir = "" Then 'did not choose folder
MsgBox "You did not choose a directory", vbCritical, "Aborting"
Exit Sub
End If
Set fso = CreateObject("Scripting.FileSystemObject")
Set Fld = fso.GetFolder(GetDir)
For Each Fil In Fld.Files
If UCase(Right(Fil.Name, 4)) = ".XLS" Then
'put your TransferSpreadsheet statement here
End If
Next Fil
MsgBox "Done
End Sub
Function GetDirectory(Optional Msg) As String
' Msg arguments allows for customized message in browser tool
Dim bInfo As BROWSEINFO
Dim path As String
Dim r As Long
Dim x As Long
Dim pos As Integer
' Root folder = Desktop
bInfo.pidlRoot = 0&
' Title in the dialog
If IsMissing(Msg) Then bInfo.lpszTitle = "Select a folder." Else bInfo.lpszTitle = Msg
' Type of directory to return
bInfo.ulFlags = &H1
' Display the dialog
x = SHBrowseForFolder(bInfo)
' Parse the result
path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, pos - 1)
Else
GetDirectory = ""
End If
End Function
Patrick