Results 1 to 19 of 19

Code to create folder and inside subfolder

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Code to create folder and inside subfolder

    Hi.

    The code below is sending back an error. It's supposed to create a folder and a subfolder within it and if the folder already exists then a msg box should pop up saying that folder already exists.

    Private Sub CommandButton1_Click()
        
    Dim xdir As String
    Dim fso
    Dim fsoSub
    Dim lstrow As Long
    Dim i As Long
    Dim xdirsubfolder As String
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fsoSub = CreateObject("Scripting.FileSystemObject")
    lstrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
    Application.ScreenUpdating = False
    For i = 1 To lstrow
    
    If Dir("\\User\" & Me.Cells(1, "A").Value, vbDirectory) = "" Then
    
    xdir = "\\User\" & Me.Cells(1, "A").Value
    xdirsubfolder = "\\User\" & Me.Cells(1, "A").Value & "\" & Me.Cells(1, "A").Value.Offset(0, 3)
    
    Else
            MsgBox "" & Me.Cells(1, "A").Value & " already exists"
    End If
    
    If Not fso.FolderExists(xdir) Then
    fso.CreateFolder (xdir)
    End If
    
    
    If Not fsoSub.FolderExists(xdirsubfolder) Then
    fsoSub.CreateFolder (xdirsubfolder)
    End If
    
    
    Next
    Application.ScreenUpdating = True
    
    End Sub
    Last edited by kosherboy; 03-07-2014 at 12:35 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel template to create Folder/Subfolder List for mp3 albums
    By stuartm456 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-27-2014, 10:27 AM
  2. Create FOLDER / SUBFOLDER from CULUM
    By mash1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-13-2012, 09:29 AM
  3. Macro to Create Folder\Sub Folder\SubFolder\
    By coolhit in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-30-2012, 12:43 PM
  4. [SOLVED] Macro to create subfolder in Oultook & directory folder
    By twitch73 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-26-2012, 09:41 PM
  5. Create folder and subfolder in four layers
    By monsterdvd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-12-2011, 05:47 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