【发布时间】:2014-09-28 23:20:52
【问题描述】:
我正在学习如何使用 Excel 宏,我发现了这段代码:
Dim fd As Office.FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
.Title = "Please select the file to kill his non colored cells"
.Filters.Add "Excel", "*.xls"
.Filters.Add "All", "*.*"
If .Show = True Then
txtFileName = .SelectedItems(1)
End If
End With
此代码打开 FileDialog。如何在不覆盖之前打开的情况下打开选定的 Excel 文件?
【问题讨论】:
-
“不覆盖之前打开的”是什么意思?此代码仅保存所选文件的路径。无论如何,如果您使用
CTRL + O打开文件,则不会覆盖文件。请澄清您的问题。 -
是的,这段代码只是保存路径,但我想打开选定的文件。如果我再次运行宏,它应该在新工作簿中打开 excel 文件。
标签: vba excel openfiledialog