濮阳杆衣贸易有限公司

主頁 > 知識庫 > 使用VBS瀏覽本地文件的3種方式,獲取完整路徑

使用VBS瀏覽本地文件的3種方式,獲取完整路徑

熱門標(biāo)簽:地圖標(biāo)注政府哪個部門管 東營快遞外呼系統(tǒng) 百度地圖標(biāo)注點距離代碼 神行者美術(shù)館地圖標(biāo)注 齊齊哈爾高德地圖標(biāo)注店 哪里有便宜的地圖標(biāo)注公司 如何用機器人進行電銷 除了地圖標(biāo)注還有這種生意嗎 佛山真人電銷機器人廠家

因為系統(tǒ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 "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

有沒有發(fā)現(xiàn)上面的代碼運行不易啊,這里腳本之家小編為大家分享一個可用的,雖然上面的的代碼不能用但學(xué)習(xí)參考一下還是不錯的,現(xiàn)在因為平臺愿意導(dǎo)致,原來這些代碼都是可以使用的。

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

好了這篇 關(guān)于vbs選擇本地文件功能的代碼就介紹到這了,需要的朋友可以參考一下。

標(biāo)簽:西安 文山 四平 邢臺 湖州 銅川 鶴壁

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《使用VBS瀏覽本地文件的3種方式,獲取完整路徑》,本文關(guān)鍵詞  使用,VBS,瀏覽,本地,文件,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《使用VBS瀏覽本地文件的3種方式,獲取完整路徑》相關(guān)的同類信息!
  • 本頁收集關(guān)于使用VBS瀏覽本地文件的3種方式,獲取完整路徑的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    望奎县| 闸北区| 开江县| 盘山县| 伊通| 马边| 隆子县| 瓮安县| 盐源县| 烟台市| 久治县| 江北区| 苗栗县| 祥云县| 涡阳县| 清水河县| 堆龙德庆县| 庄浪县| 扎鲁特旗| 施甸县| 科尔| 冀州市| 葫芦岛市| 定陶县| 余庆县| 务川| 浪卡子县| 连云港市| 苍南县| 本溪市| 高邮市| 长丰县| 越西县| 灯塔市| 齐齐哈尔市| 贵港市| 定远县| 唐河县| 冀州市| 东阳市| 米林县|