您好,感谢您查看我的问题。我正在尝试获取一个脚本来从 Access 2007 数据库中导出一组 excel 电子表格。我的导出和其他功能运行良好,这是导致我出现问题的保存功能。我当前的实现是一个消息框,显示给用户询问文件夹名称。这允许用户输入现有文件夹名称以保存到该文件夹,但前提是该文件夹已存在并且位于“我的文档”中目录。对我来说,这是功能性的,但不完全是我希望我的客户被迫处理的。有没有办法让一个简单的“另存为”或其他默认保存文件对话框出现?我有一个导入脚本在另一端工作,默认文件打开选择器工作,我错过了什么吗?脚本如下:
Private Sub btnExport_Click()
On Error GoTo Err_Command38_Click
Dim strPath As String
strPath = InputBox("Enter an existing folder name, or enter a file path.", "Export")
Beep
MsgBox "Report will now be exported to the " & strPath & " folder in My Documents"
Dim strDocName As String
strDocName = "DatabaseExport" + Date$ + ".xlsx" 'Enter your filename here
DoCmd.SetWarnings False
DoCmd.TransferSpreadsheet acExport, 10, "tblBenefit", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblBenefitDispensation", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblCourse", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblCourseEnrollment", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblDistinguishedStudent", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblEvent", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblEventFacultyAttendee", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblEventPresenter", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblEventsUniversityParticipant", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblForeignLanguageKnowledge", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblLanguage", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblGrant", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblOrganization", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblProgramRole", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblRole", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblStudent", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblStudyAbroad", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblStudyAbroadParticipation", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblTripLocation", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblUniDegreeProgram", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblUniFacultyActivity", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblUniParticipantStudentAttendee", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblUniParticipantFacultyAttendee", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblUniversity", strPath + "/" + strDocName, True
DoCmd.TransferSpreadsheet acExport, 10, "tblUniversityFaculty", strPath + "/" + strDocName, True
MsgBox "Export Complete!", vbOKOnly, ""
DoCmd.SetWarnings True
Exit_Command38_Click:
Exit Sub
Err_Command38_Click:
MsgBox Err.Description
Resume Exit_Command38_Click
End Sub
--- 结束脚本
我试过用类似的东西代替 Inputbox 方法
Dim fileSelection As Object
Set fileSelection = Application.FileDialog(2)
fileSelection.Show
Set strPath = fileSelection
但这会在 Set strPath 行上引发“需要对象”错误。感谢您提供任何帮助,谢谢!