+ Reply to Thread
Results 1 to 3 of 3

Moving files between folders using VBA in Excel

  1. #1
    Paul
    Guest

    Moving files between folders using VBA in Excel

    C:\HOLD has 2 files in it: FILE1.csv, FILE2.csv.
    I need to move the files from C:\HOLD to C:\WORK.

    The Excel Help information did not include examples of how Move and
    Movefile are actually put into practical code, and I've given up tearing my
    hair out, trying to make it work.

    Could somebody please show me the code.

    TIA
    Paul


  2. #2
    Bernie Deitrick
    Guest

    Re: Moving files between folders using VBA in Excel

    Paul,

    Sub TryNow()
    Dim FSO As Object 'FileSystemObject
    Set FSO = CreateObject("scripting.filesystemobject")
    FSO.MoveFile "c:\Hold\File*.csv", "c:\Work\File*.csv"
    End Sub

    This requires a reference to MS Scripting Runtime (Set through the VBE).

    HTH,
    Bernie
    MS Excel MVP


    "Paul" <Paul@discussions.microsoft.com> wrote in message
    news:68415C38-DFF3-43A0-BA7C-E778660351D3@microsoft.com...
    > C:\HOLD has 2 files in it: FILE1.csv, FILE2.csv.
    > I need to move the files from C:\HOLD to C:\WORK.
    >
    > The Excel Help information did not include examples of how Move and
    > Movefile are actually put into practical code, and I've given up tearing my
    > hair out, trying to make it work.
    >
    > Could somebody please show me the code.
    >
    > TIA
    > Paul
    >




  3. #3
    Jean-Yves
    Guest

    Re: Moving files between folders using VBA in Excel

    Hi,
    It would be to easy for them to call it move
    Regards
    JY
    From help

    Name Statement


    Renames a disk file, directory, or folder.

    Syntax

    Name oldpathname As newpathname

    The Name statement syntax has these parts:

    Part Description
    oldpathname Required. String expression that specifies the existing
    file name and location - may include directory or folder, and drive.
    newpathname Required. String expression that specifies the new file
    name and location - may include directory or folder, and drive. The file
    name specified by newpathname can't already exist.



    Remarks

    The Name statement renames a file and moves it to a different directory or
    folder, if necessary. Name can move a file across drives, but it can only
    rename an existing directory or folder when both newpathname and oldpathname
    are located on the same drive. Name cannot create a new file, directory, or
    folder.

    Using Name on an open file produces an error. You must close an open file
    before renaming it. Name arguments cannot include multiple-character (*) and
    single-character (?) wildcards.





    "Paul" <Paul@discussions.microsoft.com> wrote in message
    news:68415C38-DFF3-43A0-BA7C-E778660351D3@microsoft.com...
    > C:\HOLD has 2 files in it: FILE1.csv, FILE2.csv.
    > I need to move the files from C:\HOLD to C:\WORK.
    >
    > The Excel Help information did not include examples of how Move and
    > Movefile are actually put into practical code, and I've given up tearing

    my
    > hair out, trying to make it work.
    >
    > Could somebody please show me the code.
    >
    > TIA
    > Paul
    >




+ 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