0

The following code runs well if I have administrator permissions. But it doesn't work at all for a user.

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

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

End Sub

I think CATIA.FileSelectionBox() works fine in CATScript so I was thinking in run a CATScript with Application.ExecuteScript(). When I try to do it another error pops up "Function or interface marked as restricted...". Can anyone give me an alternative method? Would be very much appreciated.

Seba Sain
  • 1
  • 3
  • Is this all the code you are executing? This kind of problem generally happens when invoking a method from a typed variable. Simple by declaring it as a variant instead of it real type corrects the problem. – Quima Jun 21 '17 at 18:57
  • Thanks, I know that "Function or interface marked as restricted..." error could be solved as you say, but It did not work. Thank you again! I've already solved the problem. – Seba Sain Jun 21 '17 at 23:44

1 Answers1

0

Ok, I found my answer. Thanks for letting me post my question in here. Next, I post a code that works just fine. The only thing that remains incomplete is that I can not add filters for types of files like *.CATParts or *.CATProducts in this code. But it works for me already.

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

Kind regards

Seba Sain
  • 1
  • 3