小编Gau*_*ikh的帖子

检查文件是否只读的VBA代码

请告知如何在打开文件之前检查文件是否为只读。

这是我用来打开文件的代码:

myFileNameDir = "H:\Shaikh_Gaus\scratch\VBA\Book16.xlsx"
Workbooks.Open Filename:=myFileNameDir, UpdateLinks:=0

Set ws1 = Worksheets("Students")
Run Code Online (Sandbox Code Playgroud)

excel vba

3
推荐指数
1
解决办法
1万
查看次数

从文件路径中检索文件夹路径

我可以从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)

excel vba excel-vba

2
推荐指数
1
解决办法
1393
查看次数

标签 统计

excel ×2

vba ×2

excel-vba ×1