Private Sub Command93_Click()
Dim f As Object
Dim strFile As String
Dim strFolder As String
Dim varItem As Variant
Dim P As String
Dim DeleteEverything As String
DoCmd.SetWarnings False
DeleteEverything = "DELETE * FROM [TABLE]"
DoCmd.RunSQL DeleteEverything
Set f = Application.FileDialog(3)
f.AllowMultiSelect = False
If f.Show Then
For Each varItem In f.SelectedItems
strFile = Dir(varItem)
strFolder = Left(varItem, Len(varItem) - Len(strFile))
P = strFolder & strFile
Next
End If
Set f = Nothing
DoCmd.TransferText acImportFixed, "[IMPORT SPECIFICATION]", "[TABLE]", P, False
End Sub
如何在最初打开时将FileDialog默认为特定文件夹?
答案 0 :(得分:44)
将文件夹路径(包括尾随\
)添加到InitialFileName
。例如,要在用户的主目录中打开对话框,请执行以下操作:
f.InitialFileName = Environ("USERPROFILE") & "\"
如果忘记尾随\
,
然后对话框仍将在正确的文件夹中打开,
但文件夹名称也将显示为默认选定的文件名。
然后对话框将查找具有相同名称的子文件夹,该子文件夹通常不存在。
答案 1 :(得分:0)
我尝试了ChDir“您的\路径\这里”,并且有效
答案 2 :(得分:-1)
或者,在打开对话框之前,只需使用以下命令更改deault文件目录:
Application.Options.DefaultFilePath(wdDocumentsPath) = "your\path\here"