+ Reply to Thread
Results 1 to 2 of 2

Display particular folder using macro

Hybrid View

fblaze Display particular folder... 12-09-2014, 05:07 PM
LJMetzger Re: Display particular folder... 12-09-2014, 05:33 PM
  1. #1
    Registered User
    Join Date
    02-26-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    12

    Display particular folder using macro

    In my macro, I'm trying to display a particular folder location when the user clicks "OK" in the message box. Nothing appers when I execute the below code. Not sure what I'm missing

    ....
    Folder_Path = "C:\Users\S210\Documents"
    
    Msg = MsgBox ( "File has been created",vbOKCancel,"Success")
    
    If Msg = "Cancel" Then Exit Sub
    
    If Msg - "OK" Then
    Shell "explorer.exe /root," & Folder_Path, vbNormalFocus
    End If
    ....

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Display particular folder using macro

    Hi fblaze,

    Try the following code:
    Sub TestRunWindowsExplorer()
    
      Dim sPathAndFolder As String
      
      sPathAndFolder = ThisWorkbook.Path & "\"
      Debug.Print sPathAndFolder       'Output in debugger Immediate Window (CTRL G)
    
      Call RunWindowsExplorer(sPathAndFolder)
    
    End Sub
    
    
    Sub RunWindowsExplorer(sPathAndFolder As String)
    
      Dim sCommand As String
      Dim sLocalPathAndFolder As String
      Dim sFolder As String
      
      
      'Make sure 'Path and Folder' have a trailing 'backslash'
      'Enclose name in quadruple quotes to allow spaces in folder names
      sLocalPathAndFolder = sPathAndFolder
      If Right(sLocalPathAndFolder, 1) <> "\" Then
        sLocalPathAndFolder = sLocalPathAndFolder & "\"
      End If
      sLocalPathAndFolder = """" & sLocalPathAndFolder & """"
      
      
      
      '''''''''''''''''''''''''''''''''''''''''''''''''''
      'Open Windows Explorer for the Desired Folder
      '''''''''''''''''''''''''''''''''''''''''''''''''''
     ' Shell "cmd /c " & sPath & "   &  pause ", vbMaximizedFocus
      'Windows Explorer options see: http://support.microsoft.com/kb/152457
      ' /e   Opens Windows Explorer in its default view.
      ' /n   Opens a new single-pane window for the default selection.
      '
      ' /root,<object>    Opens a window view of the specified object.
      ' /select,<object>  Opens a window view with the specified folder, file or application selected.
      
      
      sCommand = "explorer /root," & sLocalPathAndFolder & " /select, " & sLocalPathAndFolder
     
      Call Shell(sCommand, vbNormalFocus)
     
    End Sub
    
    
    
    Public Sub LjmOpenRecycleBinInWindowsExplorer()
      'This will Open the Windows Recycle Bin in a 'Normal' Window.
      'To use a maximized window use 'vbMaximizedFocus'.
      '
      'The string ending in '954e' is the 'Recycle Bin' CLSID.
      '
      'For additional 'CLSID' information see: http://www.autohotkey.com/docs/misc/CLSID-List.htm
      '
      'Windows Explorer options see: http://support.microsoft.com/kb/152457
      ' /e   Opens Windows Explorer in its default view.
      ' /n   Opens a new single-pane window for the default selection.
      '
      ' /root,<object>    Opens a window view of the specified object.
      ' /select,<object>  Opens a window view with the specified folder, file or application selected.
      
      Dim sCommand As String
      
      sCommand = "explorer /e,::{645ff040-5081-101b-9f08-00aa002f954e}"
     
      Call Shell(sCommand, vbNormalFocus)
    End Sub
    Lewis

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 11-20-2014, 03:18 AM
  2. Display folder name in Excel - VBA Macro
    By charlests in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-19-2014, 08:40 AM
  3. Replies: 1
    Last Post: 03-12-2013, 04:45 AM
  4. Creating CULUM results - Folder / Sub Folder from excel macro
    By mash1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-13-2012, 10:19 AM
  5. To display contents of a folder in an excel sheet using Excel MACRO
    By vishucool@gmail.com in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-23-2006, 08:18 PM

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