Results 1 to 3 of 3

Browse Folder Dialog - show msgbox if nothing selected

Threaded View

  1. #1
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Browse Folder Dialog - show msgbox if nothing selected

    I'm having some trouble showing a messagebox if the user presses OK but doesn't select a folder using msoFileDialogFolderPicker. Can someone help point me in the right direction?

    Sub BrowseFolderDialog()
    Dim selectedItem As String
    
        With Application.FileDialog(msoFileDialogFolderPicker)
            .Title = "Select a Folder"
            .AllowMultiSelect = False
            .InitialFileName = ""
            If .Show = -1 Then
           
             If .SelectedItems.Count > 0 Then
                 selectedItem = .SelectedItems(1)
             End If
            
             MsgBox CStr(.SelectedItems(1))
             MsgBox selectedItem 
                    
             If Not InStr(selectedItem , ":\") Then
                 MsgBox "You didn't select a folder. The procedure has been canceled."
                 SaveSettings.OBFilePathDefault = True
                 Exit Sub
             End If
            
             
              If .SelectedItems.Count > 0 Then
                 selectedItem = .SelectedItems(1)
                 SaveSettings.TextBoxCustomPath.Text = selectedItem
                 Sheets("Back").Range("J2").Value = selectedItem
              End If
            
            Else
            MsgBox "Canceled"
            
            End If
        End With
    End Sub
    The 2 MsgBox's I've added show the same string, yet the If Not InStr line returns true regardless if ":\" is in the string or not. Any advice or other methods you can suggest?
    Last edited by VBA FTW; 05-19-2014 at 03:40 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to import .csv from browse for file location dialog box.
    By gutterball in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-30-2014, 08:30 AM
  2. Userform image browse folder, show preview and save to range
    By Mehmet82 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-04-2013, 12:47 PM
  3. [SOLVED] Get browse folder pop-up window to remember selected directory
    By IOwnAKangaroo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-06-2013, 08:57 AM
  4. Different 'Browse for Folder' dialog?
    By Jon.R in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-14-2011, 02:30 PM
  5. Excel 2010 64-bit Browse for folder Dialog box
    By c.vaibhav in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-11-2010, 02:27 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