Gau*_*ikh 2 excel vba excel-vba
我可以从filedialog函数中选择文件并将文件路径存储在字符串中.但我也想要所选路径的文件夹名称.您能否告知如何从选择文件中获取文件夹路径.
选择的文件是:
U:\public\2016\Macro\CD-CW\109 file.xlsx
Run Code Online (Sandbox Code Playgroud)
我要展示直到:
U:\public\2016\Macro\CD-CW\
Run Code Online (Sandbox Code Playgroud)
我的守则
Dim fd As Office.FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
.Title = "Please select the file."
.Filters.Clear
.Filters.Add "Excel 2010", "*.xlsx"
.Filters.Add "All Files", "*.*"
If .Show = True Then
selfile = .SelectedItems(1) 'replace txtFileName with your textbox
End If
End With
Run Code Online (Sandbox Code Playgroud)
这很简单:
Dim filePath, directoryPath As String
filePath = "U:\public\2016\Macro\CD-CW\109 file.xlsx"
directoryPath = Left(filePath, InStrRev(filePath, "\"))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1393 次 |
| 最近记录: |