我有以下代码,允许用户选择文件。那部分有效;但我希望用户将浏览的文件夹的初始位置是硬编码的。
Private Sub InputFile_Click()
Dim fDialog As Office.FileDialog
Dim filename As Variant
Dim varFile As Variant
Dim oApp As Object
Set oApp = CreateObject("Excel.Application")
' Clear listbox contents. '
Me.TextBoxName = ""
' Set up the File Dialog. '
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.AllowMultiSelect = False
' Set the title of the dialog box. '
.Title = "Please choose File"
' Clear out the current filters, and add our own.'
.Filters.Clear
.Filters.Parent = "R:\Location of where file typically resides\"
.Filters.Add "Excel csv", "*.csv"
.Filters.Add "Flat File txt", "*.txt"
.Filters.Add "All Files", "*.*"
' Show the dialog box. If the .Show method returns True, the '
' user picked at least one file. If the .Show method returns '
' False, the user clicked Cancel. '
If .Show = True Then
'Loop through each file selected and add it to our list box. '
For Each varFile In .SelectedItems
filename = Right(varFile, 51)
FileCopy varFile, "\\network\location\" & filename
Me.TextBoxName = filename
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Sub
答案 0 :(得分:0)
抱歉,我最终在StackOverflow上找到了解决方案 Defaulting a folder for FileDialog in VBA
f.InitialFileName = "[DESIRED PATH]"
现在我想知道是否有一种方法可以让最初的观点被最近的最佳观点所吸引。
InitialView = msoFileDialogViewList