Results 1 to 6 of 6

Thread: Use a list from Excel to move files on computer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Feb 2013
    Posts
    3
    Location

    Talking Use a list from Excel to move files on computer

    Ok I found this code and it works fine except that it needs the entire file name in column A to work. What I have in column A is a server name, so I need it find the server name in the file name. An example is the file name is American_server_pdol1298.mef , but in column A just the server name is listed , pdol1298 , This is the output of a script I run. So now I need to move the file into another folder.

    thank you




    [VBA]Sub MoveFiles()

    Dim Cell As Range
    Dim Filename As String
    Dim Filepath As String
    Dim NewPath As String
    Dim Rng As Range
    Dim RngEnd As Range
    Dim Wks As Worksheet

    Set Wks = ActiveSheet

    Set Rng = Wks.Range("A1")
    Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
    If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Wks.Range(Rng, RngEnd)

    For Each Cell In Rng
    Filename = Cell()
    Filepath = Cell.Offset(0, 1)
    NewPath = Cell.Offset(0, 2)
    Name Filepath & "\" & Filename As NewPath & "\" & Filename
    Next Cell

    End Sub[/VBA]
    Last edited by Bob Phillips; 02-25-2013 at 09:18 AM. Reason: Added VBA tags

Posting Permissions

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