Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Browsing for a Folder

  1. #1
    Active Member spencer.67965's Avatar
    Join Date
    2004-05
    Posts
    76
    Login to Give a bone
    0

    Question Browsing for a Folder

    Hi all,

    I was wondering if there is any way I can browse for a folder using VBA. I am trying to set a string to a user defined folder. I noticed there is getfiled which works great for files but was wondering if there is a similar function for folders.

    Thanks in advance,

    Spencer

    AutoCAD 2005, Win 2k

  2. #2
    100 Club
    Join Date
    2000-11
    Location
    Adelaide, South Australia
    Posts
    116
    Login to Give a bone
    0

    Default Re: Browsing for a Folder

    You should be able to find something here to use.
    http://www.google.com.au/search?hl=e...a=lr%3Dlang_en

  3. #3
    I could stop if I wanted to
    Join Date
    2002-02
    Location
    Kansas
    Posts
    487
    Login to Give a bone
    0

    Default Re: Browsing for a Folder

    I made a UserControl that I use to Browse for floder

    see DirList.ocx in Attach zip file
    Attached Files Attached Files

  4. #4
    Active Member spencer.67965's Avatar
    Join Date
    2004-05
    Posts
    76
    Login to Give a bone
    0

    Default Re: Browsing for a Folder

    Thanks,

    Spencer

  5. #5
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: Browsing for a Folder

    All you need is the windows api.

    Code:
    'API Constants
    Private Const MAX_PATH = 2600
    
    'API Types
    Private Type BROWSEINFO
        hOwner As Long
        pidlRoot As Long
        pszDisplayName As String
        lpszTitle As String
        ulFlags As Long
        lpfn As Long
        lParam As Long
        iImage As Long
    End Type
    
    'Declares
    Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
    Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
    
    Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
    Alias "SHGetPathFromIDListA" (ByVal pidl As Long, _
    ByVal pszPath As String) As Long
    
    
    Private Function ReturnFolder(DialogTitle As String) As String
      Dim Browser As BROWSEINFO
      Dim lngFolder As Long
      Dim strPath As String
        On Error GoTo Err_Control
      With Browser
        .hOwner = 0&
        .lpszTitle = DialogTitle
        .pszDisplayName = String(MAX_PATH, 0)
      End With
      strPath = String(MAX_PATH, 0) '<-- VERY Important!!
      lngFolder = SHBrowseForFolder(Browser)
      If lngFolder Then
        SHGetPathFromIDList lngFolder, strPath
        ReturnFolder = Left(strPath, InStr(strPath, vbNullChar) - 1)
      End If
    Exit_Here:
        Exit Function
    Err_Control:
        Select Case Err.Number
        Case Else
            MsgBox Err.Description
            Err.Clear
            Resume Exit_Here
        End Select
    End Function
    C:> ED WORKING....


    LinkedIn

  6. #6
    Active Member spencer.67965's Avatar
    Join Date
    2004-05
    Posts
    76
    Login to Give a bone
    0

    Default Re: Browsing for a Folder

    Thanks again for all your help, you all make this learing experience quite easy and enjoyable.

    Spencer

  7. #7
    I could stop if I wanted to
    Join Date
    2002-02
    Location
    Kansas
    Posts
    487
    Login to Give a bone
    0

    Default Re: Browsing for a Folder

    I like the way the API worked so over the weekend I make a use control that use the API the control as a label textbox and Commandbuton on it

    see attached file
    Attached Files Attached Files

  8. #8
    I could stop if I wanted to
    Join Date
    2002-02
    Location
    Kansas
    Posts
    487
    Login to Give a bone
    0

    Default Re: Browsing for a Folder

    you can use the Shell to Browse For a Folder
    in autocad vba
    Code:
     
    'use the shell to browseforfolder
    'Return "" if no folder
    'return the path to the floder
    Public Function GetFolder(Title As String) As String
    Dim myShell
    Dim myFolder
    Dim myFolderItem
    Dim myPath
    Set myShell = AcadApplication.GetInterfaceObject("shell.Application")
    Set myFolder = myShell.BrowseForFolder(0, Title, 0, 0)
    If myFolder Is Nothing Then
    GetFolder = ""
    Else
    Set myFolderItem = myFolder.Self
    GetFolder = myFolderItem.Path
    End If
    End Function
    or do it in Lisp
    Note: will error if on folder is selected
    Code:
     
    (vl-load-com)
    (defun getFolder()
      (if (= myshell nil)
      (setq myshell (vlax-create-object "shell.Application"))
    	()
    	)
      (setq myfolder (vlax-invoke-method myshell "BrowseForFolder" 0 "tite"0))
      (setq myfolderI(vlax-get-property  myfolder "self"))
      (setq mypaht (vlax-get-property  myfolderi "path"))
      )

  9. #9
    100 Club mtuersley's Avatar
    Join Date
    2001-12
    Posts
    122
    Login to Give a bone
    0

    Default Re: Browsing for a Folder

    The shell option was already suggested and the suggestion to use the api is always preferable over using GetInterfaceObject. Less "layers" to go through to get the same result.

  10. #10
    100 Club
    Join Date
    2002-10
    Posts
    154
    Login to Give a bone
    0

    Default Re: Browsing for a Folder

    Is there a way to get Ed's code to start from a different director (path) than MyComputer?

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 2015-07-15, 06:38 PM
  2. AutoCAD Locks Up When Browsing a Folder
    By CADdancer in forum AutoCAD General
    Replies: 2
    Last Post: 2011-08-11, 08:32 PM
  3. Replies: 0
    Last Post: 2011-05-30, 07:07 AM
  4. browsing
    By lila in forum Revit Architecture - General
    Replies: 0
    Last Post: 2007-03-02, 04:41 PM

Posting Permissions

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