我的问题是关于打开文档文件。我想让我的用户选择他想要保存文件的位置。但是,我可能错了,但我使用FileDialog(msoFileDialogFolderPicker)正常打开文件,然后向我发送错误消息!!我开始编程谢谢你的帮助。
这是我的代码
Public Function ObtenirCheminFichier(path As String)
Dim fso As Object
Dim filePath As String
Set fso = CreateObject("scripting.filesystemobject")
ObtenirCheminFichier = path
If Not fso.FileExists(path) Then
Dim tmpPath As String
tmpPath = Replace(Replace(path, ".\", "", , 1), "\", "", 1, 0)
'ObtenirCheminFichier = Application.FileDialog(msoFileDialogFolderPicker).Show()
' ObtenirCheminFichier = CurrentProject.path & "\" & tmpPath
ObtenirCheminFichier = Application.FileDialog(msoFileDialogFolderPicker) & "\" & tmpPath
End If
End Function
我怀疑这是错误的
DoCmd.OutputTo acOutputQuery, "Categorie_C2_req", acSpreadsheetTypeExcel12, spath, True
在文件夹选择器之后添加.SelectedItems(1)
,如下所示:Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
有关FileDialog对象的更多详细信息,您可以检查此API
由于您要打开单个文件,我建议您在打开文件对话框之前添加此行:Application.FileDialog(msoFileDialogFolderPicker).AllowMultiSelect = False