Académique Documents
Professionnel Documents
Culture Documents
Use the Application.FileDialog (shown in Figure 4-26, followed by sample code) to present users with a
professional pop-up dialog, from which they can select a fle.
You can use FileDialog to give user the ability to specify different flters and select multiple fles.
To use FileDialog objecg, you need to provide a reference to the Microsoft Offce 14.0 Object Library
With fd
.AllowMultiSelect = False
.Title = "Select File"
.Filters.Clear
.Filters.Add "Excel Spreadsheet", "*.xlsx"
.Filters.Add "Excel Spreadsheet", "*.xls"
.Filters.Add "Macro Enabled Workbook", "*.xlsb"
End With
End Sub
Import data from Excel Spreadsheet by Using Function
Open the form “frmFileDialog_Import_Before” in design view.
Select “Import from Excel(using function)” button and go to On Click event in the property box.
Type the following code in Visual Basic for Application
With fd
If .Show = True Then
Call importCMD(.SelectedItems(1), "tblTemp", "tblStudent_Import")
End If
End With
End Sub
Function importCMD(ByVal fileToImport As String, ByVal tempTBL As String, ByVal masterTBL As String)
On Error Resume Next
'Import data from excel sheet into tempTBL
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel5, tempTBL, fileToImport, True