+ Reply to Thread
Results 1 to 5 of 5

GetOpenFilename Properties

Hybrid View

  1. #1
    Registered User
    Join Date
    01-15-2008
    Posts
    66

    GetOpenFilename Properties

    Hi All,
    Is it possible to disable The "Look In:" field of the GetOpenFilename dialogue?
    What I would like to do is to keep users from selecting folders other than the CurrentDirectory settings and if possible to keep the user from deleting,copying and pasteing to the files in the current dirrectory displayed.

    The code I have is:

    Dim objShell As Object
     Dim fileToOpen As Variant
     Dim CurSht As String
       
       Set objShell = CreateObject("WScript.Shell")
         With objShell
          .CurrentDirectory = "f:\masters"
         End With
    
       fileToOpen = Application.GetOpenFilename("Sheets (*.xls),*.xls", 1, "aai Add Sheets")
          If fileToOpen <> False Then
            CurSht = ActiveSheet.Name
            Sheets.Add Type:=fileToOpen
            ActiveSheet.Move after:=Worksheets(CurSht)
          End If
    Last edited by dsexpress; 11-16-2008 at 05:31 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Maybe like this:
    Sub x()
        Const sDir As String = "f:\masters"
        
        Dim sFile As String
        Dim sPath
    
        ChDrive sDir
        ChDir sDir
    
        sFile = Application.GetOpenFilename("Sheets (*.xls),*.xls", 1, "aai Add Sheets")
        If sFile = "False" Then Exit Sub
        
        If Mid(sFile, InStrRev(sFile, ".") + 1) <> "xls" Then
            MsgBox "Excel files only."
            Exit Sub
        End If
        
        sPath = Left(sFile, InStrRev(sFile, "\") - 1)
        If sPath <> sDir Then
            MsgBox "Files in " & sDir & " only."
            Exit Sub
        End If
            
        Sheets.Add Type:=sFile, After:=ActiveSheet
    End Sub
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello dsexpress,

    You can modify Excel to prevent the users from copying, pasting, and deleting files from the menus. To prevent the user from opening folders, in any directory, would require overriding the Application.GetOpenFileName dialog. The problems here are the dialog is part of the Application Object, Excel, which doesn't have any parameters to enable or disable it, and Excel uses the system API call GetOpenFileNameA to dispaly the dialog. You can't change system API calls.

    Sincerely,
    Leith Ross

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Right.

    My suggestion doesn't keep users from navigating to other folders, it just keeps them from opening files in other than the specified folder.
    Last edited by shg; 11-16-2008 at 05:44 PM.

  5. #5
    Registered User
    Join Date
    01-15-2008
    Posts
    66
    Thanks ,
    That helps

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1