open a folder to view its contents

Discussion in 'AutoCAD' started by Todd, Aug 12, 2003.

  1. Todd

    Todd Guest

    Can I open a folder to view its contents from vba?
     
    Todd, Aug 12, 2003
    #1
  2. Todd

    Todd Guest

    Can I open a folder to view its contents from vba?

    Suppose I want to view the folder of "C:\temp\games\2003\August". When I
    run the macro, the window will show up containing all the contents in the
    folder.
     
    Todd, Aug 12, 2003
    #2
  3. Todd

    Ed Jobe Guest

    If all you want to do is open, "explore" that folder, then you can use the
    Shell function. Otherwise, if you are trying to do more, like return
    filenames, then you will need to use other methods.
     
    Ed Jobe, Aug 12, 2003
    #3
  4. Todd

    Matt Guest

    You can use this... (watch for wrapping).


    Option Explicit

    Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA"
    (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String,
    ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As
    Long) As Long

    Sub ShowFolder
    ShellExecute 0, "Open", "C:\temp\games\2003\August", 0, 0, 3
    End Sub
     
    Matt, Aug 13, 2003
    #4
  5. Todd

    villaco Guest

    I think this code maybe it's useful:
    this sub show you the files in the path folderspec

    Sub ShowFileList(folderspec)
        Dim fs, f, f1, fc, s
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFolder(folderspec)
        Set fc = f.Files
        For Each f1 in fc
            s = s & f1.name
            s = s & vbCrLf
        Next
        MsgBox s
    End Sub

    'this show you the folders under folderspec

    Sub ShowFolderList(folderspec)
        Dim fs, f, f1, fc, s
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFolder(folderspec)
        Set fc = f.SubFolders
        For Each f1 in fc
            s = s & f1.name
            s = s & vbCrLf
        Next
        MsgBox s
    End Sub



    Villaco
     
    villaco, Aug 13, 2003
    #5
  6. Todd

    Todd Guest

    Thanks, Matt.
     
    Todd, Aug 14, 2003
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.