Originally I had hard-coded the location and name of the Excel file. However, I cannot guarantee that the users will honour my file location and filename requirement. I found a function that lets them browse to the Excel file in order to import data from a Worksheet.
It all works very well, but since there are multiple Worksheets in the Excel file that need to be imported the current function and code I'm using causes the user to re-browse(?) each time they are ready to import the data from the next Worksheet. I'd rather not force them to go through the unnecessary step of browsing four more times for the same file.
I have a feeling that the answer is somewhere in the code, meaning it does retain the file and name location. I'm just unclear if that's true, and if so, how to use this information.
Here is the function:
Expand|Select|Wrap|Line Numbers
- Function selectFile()
- Dim fd As FileDialog
- Set fd = Application.FileDialog(msoFileDialogFilePicker)
- With fd
- If .Show Then
- selectFile = .SelectedItems(1)
- Else
- End
- End If
- End With
- Set fd = Nothing
- End Function
Expand|Select|Wrap|Line Numbers
- DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, "tblMathTempData", selectFile, True, "Math!"
Any help would be very much appreciated.