Announcement

Collapse
No announcement yet.

Test and open a directory with explorer using vba

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Test and open a directory with explorer using vba



    Hi all,

    Using VBA, I need to open a directory using Explorer or Internet Explorer, but with a condition that if the directory doesn't exists, I will receive some kind of alert that will allow me to try a diferent path.

    Thx,

    Pacheco

  • #2
    Re: Test and open a directory with explorer using vba

    Pacheco,

    Do You want to open Explorer from Excel with a specific directory open?
    Kind regards,
    Dennis

    .NET & Excel | 2nd edition PED | MVP

    Comment


    • #3
      Re: Test and open a directory with explorer using vba

      Yes, I need to open a specific directory (e.g: c:\temp), but I also need to be able to determine if that directory exists (e.g: c:\temp\test -> error)

      I tried to use the shell command:

      Dim RetVal
      RetVal = Shell("C:\windows\explorer c:\temp", 1)

      But in that way I canīt determine if that works or not.

      Thx for any hint,

      Pacheco

      Comment


      • #4
        Re: Test and open a directory with explorer using vba

        Pacheco,

        Below You find an example:


        Option Explicit

        Sub Open_Explorer()
        Dim stFolder As String

        stFolder = "c:\Temp"

        If Len(Dir(stFolder, vbDirectory)) <> 0 Then
        Shell "Explorer.exe /n,/e," & stFolder, vbNormalFocus
        Else
        MsgBox "The directory does not exist!", vbCritical
        End If

        End Sub
        Kind regards,
        Dennis

        .NET & Excel | 2nd edition PED | MVP

        Comment


        • #5
          Re: Test and open a directory with explorer using vba

          Pacheco

          You can check for the existence of a directory (or file) using the Dir statement.
          Boo!

          Comment


          • #6


            Re: Test and open a directory with explorer using vba

            Thx for your help, I will be able to finish my code now

            Pacheco

            Comment

            Working...
            X