好吧,我找到了我的答案。感謝您讓我在這裏發佈我的問題。接下來,我發佈了一個很好的代碼。唯一不完整的地方是我無法在代碼中爲* .CATParts或* .CATProducts等類型的文件添加過濾器。但它已經適用於我。
Function SelectFile()
' File Browser via HTA
' Author: Rudi Degrande, modifications by Denis St-Pierre and Rob van der
Woude
' Features: Works in Windows Vista and up (Should also work in XP).
' Fairly fast.
' All native code/controls (No 3rd party DLL/ XP DLL).
' Caveats: Cannot define default starting folder.
' Uses last folder used with MSHTA.EXE stored in Binary in
[HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32].
' Dialog title says "Choose file to upload".
' Source: https://social.technet.microsoft.com/Forums/scriptcenter/en-
US/a3b358e8-15ae-4ba3-bca5-ec349df65ef6/windows7-vbscript-open-file-dialog-
box-fakepath?forum=ITCG
Dim objExec, strMSHTA, wshShell
SelectFile = ""
' For use in HTAs as well as "plain" VBScript:
strMSHTA = "mshta.exe ""about:" & "<" & "input type=file id=FILE>" _
& "<" & "script>FILE.click();new
ActiveXObject('Scripting.FileSystemObject')" _
&
".GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);" & "<" &
"/script>"""
' For use in "plain" VBScript only:
' strMSHTA = "mshta.exe ""about:<input type=file id=FILE>" _
' & "<script>FILE.click();new
ActiveXObject('Scripting.FileSystemObject')" _
' &
".GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);
</script>"""
Set wshShell = CreateObject("WScript.Shell")
Set objExec = wshShell.Exec(strMSHTA)
SelectFile = objExec.StdOut.ReadLine()
Set objExec = Nothing
Set wshShell = Nothing
End Function
親切的問候
這是所有正在執行的代碼?從類型化變量調用方法時,通常會發生這種問題。通過將它聲明爲變體而不是真正的類型來簡化問題。 – AugustoQ
謝謝,我知道「功能或界面被標記爲受限......」錯誤可以像你說的那樣得到解決,但它不起作用。再次感謝你!我已經解決了這個問題。 –