vbs文件(怎么在VBS中浏览本地文件)

发布时间:2025-12-11 02:47:32 浏览次数:1

XP下:

FunctionBrowseForFile()'SelectFiledialogbasedonascriptbyMayayana'Knownissues:'*TreeviewalwaysopensDesktopfolder'*InWin7/IE8onlythefileNAMEisreturnedcorrectly,thepathreturnedwillalwaysbeC:\fakepath\'*Ifashortcuttoafileisselected,thenameofthatFILEwillbereturned,nottheshortcut's'OnErrorResumeNext'===========1,filebrowsererinXP==================SetobjDialog=CreateObject("UserAccounts.CommonDialog")objDialog.Filter="txt|*.txt"objDialog.InitialDir="C:\"intResult=objDialog.ShowOpenIfintResult<>0ThenBrowseForFile=objDialog.FileNameexitfunctionelsemsgbox"Error."EndIfendfunctionBrowseForFile

2003下'for windows 2003

FunctionSelectAFileSetobjDialog=CreateObject("SAFRCFileDlg.FileOpen")intResult=objDialog.OpenFileOpenDlgSelectAFile=objDialog.FileNameEndFunction

浏览器方式:

FunctionBrowseForFile()'===========2,fileselectinIE======================'AnotherwaytogetfilepathDimobjIE,strSelectedBrowseForFile=""SetobjIE=CreateObject("InternetExplorer.Application")objIE.ToolBar=FalseobjIE.Resizable=FalseobjIE.StatusBar=FalseobjIE.Width=300objIE.Height=100objIE.visible=TrueobjIE.Navigate("about:blank")DoUntilobjIE.ReadyState=4Loop'CenterthedialogwindowonthescreenWithobjIE.Document.ParentWindow.ScreenobjIE.Left=(.AvailWidth-objIE.Width)\4objIE.Top=(.Availheight-objIE.Height)\4EndWithobjIE.Document.Write"<HTML><BODY><INPUTID=""FileSelect""NAME=""FileSelect""TYPE=""file""><BODY></HTML>"WithobjIE.Document.all.FileSelect.focus.clickstrSelected=.valueEndWithobjIE.QuitSetobjIE=NothingIfTrim(strSelected)=""ThenMsgbox"Youselectednofile."Wscript.QuitEndIfBrowseForFile=strSelectedEndFunctionBrowseForFile

有没有发现上面的代码运行不易啊,这里本站小编为大家分享一个可用的,虽然上面的的代码不能用但学习参考一下还是不错的,现在因为平台愿意导致,原来这些代码都是可以使用的。

FunctionChooseFile()DimResultResult=""DimIE:SetIE=CreateObject("InternetExplorer.Application")WithIE.Visible=False.Navigate("about:blank")DoUntil.ReadyState=4:LoopWith.Document.Write"<html><body><inputid='f'type='file'></body></html>"With.All.f.Focus.ClickResult=.ValueEndWithEndWith.QuitEndWithSetIE=NothingChooseFile=ResultEndFunctionChooseFile

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注本站行业资讯频道,感谢您对本站的支持。

vbs文件
需要做网站?需要网络推广?欢迎咨询客户经理 13272073477