VB 6的新手
我想从目录或其他系统中选择一个文件。如何在VB 6中使用打开文件对话框?
需要VB 6代码帮助。
答案 0 :(得分:18)
this question中有一些示例代码。引用:
在VB6中,添加组件:
现在在表单上,从工具箱中添加新的Common Dialog控件
在代码中,您需要:
CommonDialog1.Filter = "Apps (*.txt)|*.txt|All files (*.*)|*.*"
CommonDialog1.DefaultExt = "txt"
CommonDialog1.DialogTitle = "Select File"
CommonDialog1.ShowOpen
'The FileName property gives you the variable you need to use
MsgBox CommonDialog1.FileName
答案 1 :(得分:1)
它需要“1”,但非常感谢你
CommonDialog1.Filter = "Apps (*.txt)|*.txt|All files (*.*)|*.*"
CommonDialog1.DefaultExt = "txt"
CommonDialog1.DialogTitle = "Select File"
CommonDialog1.ShowOpen
'FileName属性为您提供了需要使用的变量 MsgBox CommonDialog1.FileName
答案 2 :(得分:0)
Sub main()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Add "Excel Files", "*.xlsx; *.xlsm; *.xls; *.xlsb", 1
.Show
fullpath = .SelectedItems.Item(1)
End With
If InStr(fullpath, ".xls") = 0 Then
Exit Sub
End If
Workbooks.Open fullpath
End Sub