+ Reply to Thread
Results 1 to 3 of 3

Prompt User Folder Location and Store as Directory for Creating Folders

Hybrid View

kozman2 Prompt User Folder Location... 12-06-2017, 02:30 PM
Ton(at)FINQuality Re: Prompt User Folder... 12-06-2017, 04:36 PM
kozman2 Re: Prompt User Folder... 12-06-2017, 04:58 PM
  1. #1
    Registered User
    Join Date
    01-22-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    6

    Prompt User Folder Location and Store as Directory for Creating Folders

    I am looking to have users prompted for a folder location, I then want this to be stored to be used as the location where the values in columns A, B, C, etc.. will be created as a folder structure. I have read numerous forums and exhausted my VBA ability. The code I have below almost works but it only seems to store the name of the folder the user chooses then creates a folder with the user choice and the value in column A appended to it, sub folders create as expected. Thank you for any help!

    Sub CreateStructure()
    Dim i As Long
    Dim fdDrive As FileDialog
    Dim strDrive As String
    Dim strlevel1 As String
    Dim strLevel2 As String
    
    Set fdDrive = Application.FileDialog(msoFileDialogFolderPicker)
    With fdDrive
        .Title = "Select a Folder"
        .AllowMultiSelect = False
        .InitialFileName = Application.DefaultFilePath
        If .Show <> -1 Then GoTo NextCode
        strDrive = .SelectedItems(1)
        End With
    
    NextCode:
        GetFolder = strDrive
        Set fdDrive = Nothing
    
    With Sheets(1).Range("A1")
        strlevel1 = .Offset(0, 0)
        MkDir strDrive & strlevel1
        For i = 1 To Sheets(1).UsedRange.Rows.Count - 1
            If .Offset(i, 0) = "" Then
                If .Offset(i, 1) <> "" Then
                    strLevel2 = .Offset(i, 1)
                    MkDir strDrive & strlevel1 & "\" & strLevel2
                Else
                    MkDir strDrive & strlevel1 & "\" & strLevel2 & "\" & .Offset(i, 2)
               End If
            Else
                strlevel1 = .Offset(i, 0)
                MkDir strDrive & strlevel1
            End If
        Next i
    End With
    End Sub

  2. #2
    Registered User
    Join Date
    11-21-2016
    Location
    Emmen, The Netherlands
    MS-Off Ver
    MS Office 365 ProPlus
    Posts
    19

    Re: Prompt User Folder Location and Store as Directory for Creating Folders

    Hi kozman2,

    Didn't understand exactly what you got, but I think the problem is nog adding the slash after strDrive.

    MkDir strDrive & "\"

    Hope this works.

    Ton

  3. #3
    Registered User
    Join Date
    01-22-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Prompt User Folder Location and Store as Directory for Creating Folders

    Apologize if it wasn't clear but you were correct. Code below fixed the problem. Thanks!

    Sub CreateStructure()
    Dim i As Long
    Dim fdDrive As FileDialog
    Dim strDrive As String
    Dim strlevel1 As String
    Dim strLevel2 As String
    
    Set fdDrive = Application.FileDialog(msoFileDialogFolderPicker)
    With fdDrive
        .Title = "Select a Folder"
        .AllowMultiSelect = False
        .InitialFileName = Application.DefaultFilePath
        If .Show <> -1 Then GoTo NextCode
        strDrive = .SelectedItems(1)
        End With
    
    NextCode:
        GetFolder = strDrive
        Set fdDrive = Nothing
    
    With Sheets(1).Range("A1")
        strlevel1 = .Offset(0, 0)
        MkDir strDrive & "\" & strlevel1
        For i = 1 To Sheets(1).UsedRange.Rows.Count - 1
            If .Offset(i, 0) = "" Then
                If .Offset(i, 1) <> "" Then
                    strLevel2 = .Offset(i, 1)
                    MkDir strDrive & "\" & strlevel1 & "\" & strLevel2
                Else
                    MkDir strDrive & "\" & strlevel1 & "\" & strLevel2 & "\" & .Offset(i, 2)
               End If
            Else
                strlevel1 = .Offset(i, 0)
                MkDir strDrive & strlevel1
            End If
        Next i
    End With
    End Sub

+ 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. Open Folder (Prompt User for final folder name in location path)
    By synergeticink in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2014, 03:33 PM
  2. [SOLVED] Buttons to prompt for directroy. Paste directory location in corresponding cell.
    By mamero in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-27-2013, 09:19 PM
  3. [SOLVED] Prompt to insert user name in directory
    By jh51745 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-03-2013, 10:01 AM
  4. [SOLVED] Macro to prompt user for folder location and save acitve workbook.
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2013, 06:20 PM
  5. Prompt User for Directory(folder)
    By cocotrp in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-14-2011, 06:37 PM
  6. Replies: 3
    Last Post: 06-11-2009, 07:08 PM
  7. prompt user to specify a directory
    By mini in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-20-2006, 01:10 AM

Tags for this Thread

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