none
Create Folder With Excel Cell

    Question

  • Is it possible to have a folder created by a user that runs a macro on an excel file, reading the name from Cell A1 and creating

    the folder with that text?

     

    Wednesday, December 07, 2011 8:12 PM

Answers

  • Sub test

    CreateDirectory("c:\" & range("A1").value)

    End sub

    Private Sub CreateDirectory(ByVal FolderPath As String)
    If Len(Dir(FolderPath, vbDirectory)) = 0 Then
         MkDir FolderPath
     End If
    End Sub

    Wednesday, December 07, 2011 8:19 PM

All replies

  • Sub test

    CreateDirectory("c:\" & range("A1").value)

    End sub

    Private Sub CreateDirectory(ByVal FolderPath As String)
    If Len(Dir(FolderPath, vbDirectory)) = 0 Then
         MkDir FolderPath
     End If
    End Sub

    Wednesday, December 07, 2011 8:19 PM
  • Thank you!

    How about creating a copy of that file on that folder recently created?

    Wednesday, December 07, 2011 8:39 PM
  • Im not understanding what your wanting. Copy of what file?
    Wednesday, December 07, 2011 8:43 PM
  • The excel file where I am creating the folder, I would need to save on that folder recently created.
    Wednesday, December 07, 2011 9:04 PM
  • Also, If the path is:

    c:\temp\year\month\day\Open

    And the excel file has a cell that contains the date. Is it possible that the macro will recognize the month and date and actually create the folder using that path?

    For example:

    Name of the folder: Cell A1: XCETFGYHF

    Date: Cell F1: 12/07/2011

    then the folder that I need to create would be:

    c:\temp\2011\Dec\07\Open\XCETFGYHF

    Wednesday, December 07, 2011 9:10 PM
  • Try this

    Sub test()
        Dim sYear As String, sMonth, sDay, sFolder, temp

        sYear = Format(Range("f11"), "YYYY")
        sMonth = Format(Range("f11"), "MMM")
        sDay = Format(Range("f11"), "dd")

        sFolder = "temp;" & sYear & ";" & sMonth & ";" & sDay & ";Open;" & Range("A1").Value
        arrFolder = Split(sFolder, ";")
        For intIndex = LBound(arrFolder) To UBound(arrFolder)
            temp = temp & "\" & arrFolder(intIndex)
            CreateDirectory ("c:" & stemp)
        Next
    End Sub

    Wednesday, December 07, 2011 10:18 PM
  • Sub of function not defined

     

    Wednesday, December 07, 2011 10:26 PM
  • Sub test()
    Dim sYear As String, sMonth, sDay, sFolder, temp

    sYear = Format(Range("f11"), "YYYY")
    sMonth = Format(Range("f11"), "MMM")
    sDay = Format(Range("f11"), "dd")

    sFolder = "temp;" & sYear & ";" & sMonth & ";" & sDay & ";Open;" & Range("A1").Value
    arrFolder = Split(sFolder, ";")
    For intIndex = LBound(arrFolder) To UBound(arrFolder)
    temp = temp & "\" & arrFolder(intIndex)
    CreateDirectory ("c:" & stemp)
    Next
    End Sub

    Private Sub CreateDirectory(ByVal FolderPath As String)
    If Len(Dir(FolderPath, vbDirectory)) = 0 Then
    MkDir FolderPath
    End If
    End Sub

    Wednesday, December 07, 2011 10:27 PM
  • So basically I need to also merge it with the other macro so after the date, the folder can be created using the data con A1.

     

    Wednesday, December 07, 2011 10:27 PM
  • Post your code you are working with.
    Wednesday, December 07, 2011 10:31 PM
  • Sub RMA_tree()

    CreateDirectory ("C:\Users\juanpablo.ADVANCED.000\Documents\Project\RMA\ANU\Rep 1\Dec\01\01_Open\" & Range("D1").Value)

    End Sub

    Private Sub CreateDirectory(ByVal FolderPath As String)
    If Len(Dir(FolderPath, vbDirectory)) = 0 Then
         MkDir FolderPath
     End If
    End Sub
    the only problem is that the file will have to go in different folders depending on the date that is in cell F1
    So if cell F1 is 12/07/2011
    I need to have the files saved in:
    Documents\Project\RMA\ANU\Rep 1\Dec\07\01_Open\
    Wednesday, December 07, 2011 11:32 PM
  • Doesnt work.
    Thursday, December 08, 2011 3:02 AM
  • hallo

    thanks this worked for me.

    I have another question, how to increase the range?

    Now it creates only for cell A1. Also how to change the folder path?

    Thanks in advance.

    Thursday, October 24, 2013 2:50 PM