ليس لدي أوفيس 2003 ، ولكن جرب هذا التعديل لزر التصدير ..
Private Sub cm_ToExcel_Click()
On Error GoTo Err_cm_ToExcel_Click
Dim stDocName As String
Dim filePath As String
Dim defaultFolder As String
Dim Q As Integer
Dim fd As Object
stDocName = "tbl_Teacher" & [Year_name]
defaultFolder = "D:\Access_Teacher\"
Q = DCount("*", "tbl_Teacher")
If Q > 0 Then
If Dir(defaultFolder, vbDirectory) = "" Then
MkDir defaultFolder
End If
Set fd = Application.FileDialog(2)
With fd
.Title = "اختر مكان حفظ ملف الإكسل"
.InitialFileName = defaultFolder & stDocName & ".xls"
If .Show = -1 Then
filePath = .SelectedItems(1)
If LCase(Right(filePath, 4)) <> ".xls" Then
filePath = filePath & ".xls"
End If
DoCmd.TransferSpreadsheet acExport, 8, "tbl_Teacher", filePath, False
MsgBox "تم استخراج ملف الإكسل بنجاح وحفظه في:" & vbCrLf & vbCrLf & _
filePath, vbInformation + vbMsgBoxRight, ""
End If
End With
Else
MsgBox "لا يوجد سجلات لتصديرها", vbOKOnly + vbMsgBoxRight, ""
End If
Exit_cm_ToExcel_Click:
Exit Sub
Err_cm_ToExcel_Click:
MsgBox Err.Description, vbCritical + vbMsgBoxRight, "خطأ"
Resume Exit_cm_ToExcel_Click
End Sub
قمت بتعديل الزر بحيث يعتمد اسم المسار الذي حددته لنا ، وإنشاء المجلد نفسه في المسار إذا لم يكن موجوداً ..