一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - VBS - 使用VBS瀏覽本地文件的3種方式,獲取完整路徑

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

2020-08-20 10:48VBS教程網 VBS

這篇文章主要介紹了使用VBS瀏覽本地文件的3種方式,獲取完整路徑,需要的朋友可以參考下

因為系統組件差異,所以代碼也有不同文章最后服務器之家給出一個通用的代碼

XP下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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

?
1
2
3
4
5
Function SelectAFile
Set objDialog = CreateObject("SAFRCFileDlg.FileOpen")
intResult = objDialog.OpenFileOpenDlg
SelectAFile = objDialog.FileName
End Function

瀏覽器方式:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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

有沒有發現上面的代碼運行不易啊,這里服務器之家小編為大家分享一個可用的,雖然上面的的代碼不能用但學習參考一下還是不錯的,現在因為平臺愿意導致,原來這些代碼都是可以使用的。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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選擇本地文件功能的代碼就介紹到這了,需要的朋友可以參考一下。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产成人无精品久久久久国语 | 亚洲美色综合天天久久综合精品 | 大陆国语自产精品视频在 | 好紧好爽再叫浪一点点潘金莲 | 日韩福利网| 国产在线精品成人一区二区三区 | 舔比小说 | 好大好猛好爽好深视频免费 | 国产成人久久久精品一区二区三区 | 高h细节肉爽文办公室 | 日韩一区二区三区四区不卡 | 91在线视频国产 | 国产区成人精品视频 | 亚洲四虎永久在线播放 | caoporn国产| 精品国产原创在线观看视频 | 免费高清www动漫视频播放器 | 边摸边吃奶边做爽gif动态图 | 8x8x拔插 | 国产精品视频视频久久 | 女同videos双性人 | 国产精品香蕉夜间视频免费播放 | 午夜精品网| 天若有情1992国语版完整版 | 火影小南被爆羞羞网站 | 美味情缘韩国在线观看视频 | 甜宠巨肉h文1v1校园 | 性xxxxxxx18老师 | 国产不卡视频 | 无码国产成人777爽死在线观看 | 国产实拍会所女技师在线 | 人与善交大片免费看 | 国自产拍在线天天更新91 | 91庥豆果冻天美精东蜜桃传媒 | 天天射夜夜爽 | 果冻传媒在线视频播放观看 | 成人精品视频 成人影院 | 国产成人一区二区三区小说 | 99er热| 成年人在线免费看 | 欧美二区视频 |