+ Reply to Thread
Results 1 to 7 of 7

Creating a folder and copying files to it

  1. #1
    Registered User
    Join Date
    01-05-2007
    Posts
    13

    Creating a folder and copying files to it

    Hello All,
    Please if this question has been asked before kindly direct me to the solution, else please do assist.
    I need to do a VBA to creat a folder and copy some specific files to the new folder. I have achieved creating the folder but to copy files to it is my trouble.
    See below the code I have put together and it's not solving my problem.


    Sub folder()
    Dim strPath As String
    Dim SourceFile, DestinationFile
    ' creating folder
    strPath = InputBox("Enter folder Name", "Create Folder")
    MkDir "C:\CLass\" & strPath
    'Copying files
    SourceFile = "C:\board\xxx.xls"
    DestinationFile = "C:\CLass\" & strPath
    End Sub

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Have a look at the help for filecopy

    Dim SourceFile, DestinationFile
    SourceFile = "SRCFILE" ' Define source file name.
    DestinationFile = "DESTFILE" ' Define target file name.
    FileCopy SourceFile, DestinationFile ' Copy source to target.
    Martin

  3. #3
    Registered User
    Join Date
    01-05-2007
    Posts
    13

    Re:Creating a folder and copying files to it

    Mrice,
    I guess you did not look at the code I posted before replying.
    I have tried what you just suggested and it is not working for me.
    Please is there any other way to get arround this

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Your code is missing the line

    FileCopy SourceFile, DestinationFile ' Copy source to target.

  5. #5
    Registered User
    Join Date
    01-05-2007
    Posts
    13
    Mrice ,
    Apologies, you were right, I did miss that line of code while I was posting the code to the forum.
    I am still not getting this code to run with the whole piece in place.

  6. #6
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Ah!

    It might be that you need to include the path and file name in the destination as opposed to just the path. This functionality allows the file name to be changed as well.

  7. #7
    Registered User
    Join Date
    01-05-2007
    Posts
    13
    Mrice,
    your suggestion worked out well.
    But the problem is the code does not copy files to the new folder that I created using the inputbox syntax.
    I tried using already existing folders and the code worked , but when I create a new folder through the inputbox prompt it does not copy the files to it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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