我正在学习如何使用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文件的情况下打开选定的Excel文件?
最新回答
- 2021-1-101 #
- 2021-1-102 #
除非我误解了您的问题,否则您只能打开一个只读文件。 这是一个简单的示例,没有进行任何检查。
要从用户获取文件路径,请使用以下功能:
Private Function get_user_specified_filepath() As String 'or use the other code example here. Dim fd As Office.FileDialog Set fd = Application.FileDialog(msoFileDialogFilePicker) fd.AllowMultiSelect = False fd.Title = "Please select the file." get_user_specified_filepath = fd.SelectedItems(1) End Function
然后仅以只读方式打开文件并将其分配给变量:
dim wb as workbook set wb = Workbooks.Open(get_user_specified_filepath(), ReadOnly:=True)
相关问题
- excel vba:如何在VBA中连接字符串?excelvbavbaexcel2021-01-11 22:58
- Vba Excel从关闭的文件执行vlookupexcelvbaexcelvbaexcelformulavlookup2021-01-07 06:56
- Excel VBA"对象'IwebBrowser2'的方法'文档'失败"excelvbaexcelvbawebscraping2021-01-07 08:54
- Excel VBA删除行excelvbaexcelvba2021-01-07 09:52
- 使用通配符打开Excel工作簿excelexcelvbawildcardvba2021-01-07 15:25
谢谢Frank.i有了这个想法。 这是工作代码。