تفضل أخي الكريم ، التعديل الي طلبته ..
Private Sub btnLocateFile_Click()
On Error GoTo Err_btnLocateFile_Click
Dim fd As Object
Dim fileName As String
Dim defaultFolder As String
defaultFolder = "D:\Access_Teacher\"
If Dir(defaultFolder, vbDirectory) = "" Then
MkDir defaultFolder
End If
Set fd = Application.FileDialog(1)
With fd
.Title = "اختر ملف الإكسل"
.Filters.Clear
.Filters.Add "Excel Files", "*.xls; *.xlsx"
.InitialFileName = defaultFolder
If .Show = -1 Then
If .SelectedItems.Count > 0 Then
fileName = .SelectedItems(1)
Me.txtImportFile = fileName
End If
End If
End With
Exit_btnLocateFile_Click:
Exit Sub
Err_btnLocateFile_Click:
MsgBox Err.Description, vbCritical + vbMsgBoxRight, "خطأ"
Resume Exit_btnLocateFile_Click
End Sub