Consulting

Results 1 to 7 of 7

Thread: Solved: CopyFile If

  1. #1
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location

    Solved: CopyFile If

    How can i copy every file in a folder to a new location that starts with 12345 please


    Cheers

    Gibbo

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    [vba]Sub CopyEm()
    Dim FSO As Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
    'set your paths below
    FSO.CopyFolder "C:\Windows\Desktop\New Folder", "C:\Windows\Desktop\12345"
    Set FSO = Nothing
    End Sub[/vba]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  3. #3
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Gibbo

    Do you mean every file that starts with 12345?

  4. #4
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    sorry norie, i did mean every spreadsheet that starts with 12345 in the same folder (e.g. C:\Test)

    So 12345A.xls
    12345B.xls and so on

    Cheers gibbo

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [VBA]
    Sub CopyEm()
    Dim oFSO As Object
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    'set your paths below
    oFSO.CopyFile "C:\MyTest\12345*.xls", "C:\NewDir\"
    Set oFSO = Nothing
    End Sub
    [/VBA]

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Gibbo,
    A minor adjustment to johnske's code to do this
    [VBA]
    Sub CopyEm()
    Dim FSO As Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
    'set your paths below
    FSO.CopyFile "C:\Location\12345*.xls", "C:\NewLocation\"
    Set FSO = Nothing
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    I ve been racking my brains for hours and its that simple


    thank you for putting me right

    Gibbo

Posting Permissions

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