[Solved] problems creating new folders and files

  • Hi, I have a little problem with the following code:


    Sub aanmaak_folder()
    Dim i_folder As String
    Dim i_cel As Integer
    Dim a As String
    Dim b As String


    Const OverwriteExisting = True
    Set obj = CreateObject("Scripting.FileSystemObject")
    Set objfile = CreateObject("Scripting.FileSystemObject")


    i_cel = 1


    While i_cel < 6


    i_folder = Cells(i_cel, 1).Value ‘values of cell a1:a5 are the names of the folders


    a = "C:\" & i_folder


    Set objFolder = obj.CreateFolder(a)


    b = "C:\" & i_folder & "\" & i_folder & ".xls" ‘the file name must be the same as the folder name


    objfile.CopyFile "C:\tag\copyfiletest.xls", "b", OverwriteExisting


    i_cel = i_cel + 1


    Wend


    End Sub


    This code makes automatically dir. with the names stored in cells a1:a6. (“tag1”,”tag2” to “tag5”)
    This is working well. But the workbook copyfiletest.xls must be copied under each new folder and renamed with the same folder name. Here is the problem: there are no files copied only the folders are created.
    I don’t know where the problem is?


    Eg "C:\test\copyfiletest.xls"
    -&gt; "C:\tag1\tag1.xls"

    -&gt; "C:\tag2\tag2.xls"


    thanx,
    Fluppe

  • Hi Fluppe


    Instead of
    objfile.CopyFile "C:\tag\copyfiletest.xls", "b", OverwriteExisting


    try
    objfile.CopyFile "C:\tag\copyfiletest.xls", b, OverwriteExisting


    HTH

    There are three types of people in this world.
    Those who can count and those who can&#039;t.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!