Results 1 to 2 of 2

Thread: Move file and create folder

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    1

    Move file and create folder

    Hi All,

    I am kinda new on VBA and I am trying to create a Macro to help me on a project.
    I have a 2 collumn Excel file with x rows

    A1.value = Filename.ext
    B1.value = Full_Folder_Path

    On my hard drive, all files (at least most) are under the same root folder C:\S\

    I would like the VBA mcro to read the excel file and make the following actions:


    Read A1
    Move A1 file from root folder S to Path on B2

    Loop
    Read B2
    ... Till Ax

    Sub copyfiles()
    Dim x As Long, a As Long
    x = Cells(Rows.Count, 1).End(xlUp).Row
    For a = 1 To x
    FileCopy "C:\S\" & Cells(a, 1).Value, Cells(a, 2).Value
    Next a
    End Sub

    For some reason this is not working.

    Any ideas would be much appreciated.

    Thanks !

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Move file and create folder

    For some reason this is not working
    what happens error?
    wrong result?
    nothing?

    as you want to move the file, you should use name rather than filecopy
    try like
    Code:
    Name "C:\S\" & Cells(a, 1).Value As Cells(a, 2).Value & "\" & Cells(a, 1).Value
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width