兴国资源网 Design By www.nnzcdc.com
因为系统组件差异,所以代码也有不同文章最后给出一个通用的代码
XP下:
Function BrowseForFile( ) ' Select File dialog based on a script by Mayayana ' Known issues: ' * Tree view always opens Desktop folder ' * In Win7/IE8 only the file NAME is returned correctly, the path returned will always be C:\fakepath' * If a shortcut to a file is selected, the name of that FILE will be returned, not the shortcut's 'On Error Resume Next '===========1, file browserer in XP ================== Set objDialog = CreateObject("UserAccounts.CommonDialog") objDialog.Filter = "txt|*.txt" objDialog.InitialDir = "C:\" intResult = objDialog.ShowOpen If intResult <> 0 Then BrowseForFile = objDialog.FileName exit function else msgbox "Error." End If end function BrowseForFile
2003下'for windows 2003
Function SelectAFile Set objDialog = CreateObject("SAFRCFileDlg.FileOpen") intResult = objDialog.OpenFileOpenDlg SelectAFile = objDialog.FileName End Function
浏览器方式:
Function BrowseForFile( ) '===========2, fileselect in IE ====================== 'Another way to get file path Dim objIE, strSelected BrowseForFile = "" Set objIE = CreateObject( "InternetExplorer.Application" ) objIE.ToolBar = False objIE.Resizable = False objIE.StatusBar = False objIE.Width = 300 objIE.Height = 100 objIE.visible = True objIE.Navigate( "about:blank" ) Do Until objIE.ReadyState = 4 Loop ' Center the dialog window on the screen With objIE.Document.ParentWindow.Screen objIE.Left = (.AvailWidth - objIE.Width ) \ 4 objIE.Top = (.Availheight - objIE.Height) \ 4 End With objIE.Document.Write "<HTML><BODY><INPUT ID=""FileSelect"" NAME=""FileSelect"" TYPE=""file""><BODY></HTML>" With objIE.Document.all.FileSelect .focus .click strSelected = .value End With objIE.Quit Set objIE = Nothing If Trim(strSelected) = "" Then Msgbox "You selected no file." Wscript.Quit End If BrowseForFile = strSelected End Function BrowseForFile
有没有发现上面的代码运行不易啊,这里小编为大家分享一个可用的,虽然上面的的代码不能用但学习参考一下还是不错的,现在因为平台愿意导致,原来这些代码都是可以使用的。
Function ChooseFile() Dim Result Result = "" Dim IE : Set IE = CreateObject("InternetExplorer.Application") With IE .Visible = False .Navigate("about:blank") Do Until .ReadyState = 4 : Loop With .Document .Write "<html><body><input id='f' type='file'></body></html>" With .All.f .Focus .Click Result = .Value End With End With .Quit End With Set IE = Nothing ChooseFile = Result End Function ChooseFile
好了这篇 关于vbs选择本地文件功能的代码就介绍到这了,需要的朋友可以参考一下。
兴国资源网 Design By www.nnzcdc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
兴国资源网 Design By www.nnzcdc.com
暂无评论...
更新日志
2024年05月01日
2024年05月01日
- 新民樂演奏《蘭閨寂寂上海管弦楽團伴奏》[WAV+CUE]
- 《半吨兄弟单曲合集100首》[WAV分轨][3.1G]
- 群星《经典粤语老歌》原音母版1:1直刻 [WAV+CUE][671M]
- 《张宇4CD合集》[WAV分轨][1.5G]
- 柳岩.2009-岩色EP【光线】【WAV+CUE】
- 戚薇.2012-如果爱忘了(EP)【海蝶】【WAV+CUE】
- 群星.2005-华纳至尊金曲1+2XRCD【华纳】【WAV+CUE】
- 徐霞《那就是我》[太平洋影音][WAV+CUE]
- 姚斯婷《爱那么重》蓝光头版限量编号[低速原抓WAV分轨]
- 【古典音乐】奥芙拉·哈诺依《爱的礼赞-浪漫大提琴》1999[FLAC+CUE/整轨]
- 沙特电竞世界杯官宣7.3开赛!赛程比足球世界杯还长
- 恐怖片版《小美人鱼》来了!童话爆改爱上远古人鱼
- 萧正楠.2004-故事【大国文化】【WAV+CUE】
- 黄小玫.2024-Appreciation【FLAC分轨】
- 李雨.2024-愚人谷及其寓言的往来【大象无形】【FLAC分轨】