View Full Version : VBA Newbee


khurman
07-16-2008, 04:51 PM
Hi,
I have a series of timesheets (sample attached) that I need to extract data from. For this purpose I am using code attached below. I would appreciate if some one can point me to the following.

1. how can i search for files in subfolders.
2. can i extract name too from each timesheet for each record or is it a good idea to have separate tables for each user

:

Sub Link_To_Excel()
'WillR - www.willr.info (http://www.willr.info) (December 2004)
'Macro Loops through the specified directory (strPath)
'and links ALL Excel files as linked tables in the Access
'Database.

Const strPath As String = "C:\" 'Directory Path
Dim strFile As String 'Filename
Dim strFileList() As String 'File Array
Dim intFile As Integer 'File Number

'Loop through the folder & build file list
strFile = Dir(strPath & "*.xls")
While strFile <> ""
'add files to the list
intFile = intFile + 1
ReDim Preserve strFileList(1 To intFile)
strFileList(intFile) = strFile
strFile = Dir()
Wend
'see if any files were found
If intFile = 0 Then
MsgBox "No files found"
Exit Sub
End If
'cycle through the list of files & import to Access
'creating a new table called Test2
For intFile = 1 To UBound(strFileList)
DoCmd.TransferSpreadsheet acImport, , _
"Test2", strPath & strFileList(intFile), True, "A7:H19"
'Check out the TransferSpreadsheet options in the Access
'Visual Basic Help file for a full description & list of
'optional settings
Next
MsgBox UBound(strFileList) & " Files were Imported"
End Sub

georgedwilkinson
07-16-2008, 07:38 PM
1. Use the VBA command "Dir()".
2. Don't under any circumstances create a new table for each user (whatever that means). Sounds like you may need to read up on basic relational database theory before attempting this.