Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Move files with vba within Excel (xp, win2000)

    I have done a macro in Excel xp that updates some excel files with new text files coming in. I want to move the text files to a folder called "old" after the macro is done. Can someone help me with some vba code in excel to do this. Thanks a lot.

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Move files with vba within Excel (xp, win2000)

    Try something like this:

    <pre>Dim fs As New FileSystemObject
    fs.MoveFile "C:MyDirMyFile.txt", "C:MyDirOld"
    </pre>


    Make sure that the Microsoft Scripting Runtime reference is checked under Tools/References before trying to use this.
    Legare Coleman

  3. #3
    New Lounger
    Join Date
    Jan 2001
    Location
    Nova Scotia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Move files with vba within Excel (xp, win2000)

    The command you are looking for is the Name statement.

    Name oldpathname as newpathname

    From the VBA help:

    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

Posting Permissions

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