不用组件的话有两种办法:
setobjFile=CreateObject("SAFRCFileDlg.FileOpen")
SetobjShell=CreateObject("Shell.Application")
本blog里都有示例。
如果调用vb组件,可以是:
flag=&h200
whichone=OpenFile("ChooseaFile!","C:","Everything|*.*|TextFiles|*.TXT|Word-Documents|*.DOC",2,flag)
MsgBox"Rawdatareturned:"&whichone
'Splitupmultiselectionresult:
'spaceisusedasseparator:
whichone=Split(whichone,"")
'fieldindex0containspathinformation:
path=whichone(0)
'listallthefiles:
'howmanyfileswereselected?
filecount=UBound(whichone)
iffilecount=0then
'justonefileselected!
MsgBox"Youselectedonefile:"&whichone(0)
'checkstatusofReadOnlycheckbox
'isbit1setorcleared?
'worksonlyifjustonefilewasselected!
MsgBox"Returnedflag:"&flag
if(flagand1)then
'(flagand1)<>0,transformstotrue
'bitisset!
MsgBox"ReadOnlyselected!"
else
MsgBox"ReadOnlynotselected!"
endIf
'checkwhetherselectedfileisofdefaulttype(txt)
if(flagand1024)then
MsgBox"selectedfileisnotxtfile!"
else
MsgBox"selectedfileisofdefaulttype!"
endif
else
'morethanonefileselected!
MsgBox"Youselected"&filecount&"files!"
forx=1toUBound(whichone)
list=list&path&whichone(x)&vbCr
next
MsgBoxlist
endIf
functionOpenFile(title,dir,filter,index,flags)
setcomdlg=CreateObject("MSComDlg.CommonDialog")
comdlg.filter=filter
comdlg.FilterIndex=index
comdlg.Flags=flags
comdlg.MaxFileSize=260
comdlg.CancelError=false
comdlg.DialogTitle=title
comdlg.InitDir=dir
'settxtasdefault
comdlg.DefaultExt="txt"
comdlg.ShowOpen
OpenFile=comdlg.filename
'important:returnflagstatussoyourmainscriptcan
'checkit:
flags=comdlg.Flags
endfunction
组件相关文件下载http://xiazai.jb51.net/jbtools/vb6controls.rar