新手 Application.FileDialog打开文件问题
Sub usefiledialog()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Excel Files", "*.xls;*.xlw"
.Filters.Add "All Files", "*.*"
If .Show = -1 Then
MsgBox "您选择的文件是:" & .SelectedItems(1), vbOKOnly + vbInformation, "智能Excel"
End If
End With
End Sub
我点了确定了 怎么没有实际打开文件呢??
[解决办法]
Sub a()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Excel Files", "*.xls;*.xlw"
.Filters.Add "All Files", "*.*"
If .Show = -1 Then
MsgBox "您选择的文件是:" & .SelectedItems(1), vbOKOnly + vbInformation, "智能Excel"
f = .SelectedItems(1) '取文件名
End If
End With
'打开文件
Application.Workbooks.Open f
End Sub