怎么在VBS中瀏覽本地文件?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。
專業(yè)領(lǐng)域包括成都網(wǎng)站制作、做網(wǎng)站、購(gòu)物商城網(wǎng)站建設(shè)、微信營(yíng)銷、系統(tǒng)平臺(tái)開發(fā), 與其他網(wǎng)站設(shè)計(jì)及系統(tǒng)開發(fā)公司不同,創(chuàng)新互聯(lián)的整合解決方案結(jié)合了幫做網(wǎng)絡(luò)品牌建設(shè)經(jīng)驗(yàn)和互聯(lián)網(wǎng)整合營(yíng)銷的理念,并將策略和執(zhí)行緊密結(jié)合,為客戶提供全網(wǎng)互聯(lián)網(wǎng)整合方案。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 "" 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
有沒有發(fā)現(xiàn)上面的代碼運(yùn)行不易啊,這里創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,小編為大家分享一個(gè)可用的,雖然上面的的代碼不能用但學(xué)習(xí)參考一下還是不錯(cuò)的,現(xiàn)在因?yàn)槠脚_(tái)愿意導(dǎo)致,原來(lái)這些代碼都是可以使用的。
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 "" With .All.f .Focus .Click Result = .Value End With End With .Quit End With Set IE = Nothing ChooseFile = Result End Function ChooseFile
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,的支持。