2017-06-19 169 views
0

如果我擁有管理員權限,以下代碼運行良好。但它對用戶來說根本不起作用。如何解決CATIA.FileSelectionBox()錯誤,而無需以管理員身份設置「regserver option」?

Sub CATMain() 
On Error Resume Next 
Dim strpath As String 

strpath = CATIA.FileSelectionBox("Select file", "*.xlsx", 
CatFileSelectionModeOpen) 

End Sub 

我認爲CATIA.FileSelectionBox()工作正常CATScript所以我在奔跑與Application.ExecuteScript一個CATScript()的思想。當我嘗試這樣做時會彈出另一個錯誤「功能或界面被標記爲受限制...」。任何人都可以給我一種替代方法嗎?將非常感激。

+0

這是所有正在執行的代碼?從類型化變量調用方法時,通常會發生這種問題。通過將它聲明爲變體而不是真正的類型來簡化問題。 – AugustoQ

+0

謝謝,我知道「功能或界面被標記爲受限......」錯誤可以像你說的那樣得到解決,但它不起作用。再次感謝你!我已經解決了這個問題。 –

回答

0

好吧,我找到了我的答案。感謝您讓我在這裏發佈我的問題。接下來,我發佈了一個很好的代碼。唯一不完整的地方是我無法在代碼中爲* .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 

親切的問候

相關問題