• Move files with vba within Excel (xp, win2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Move files with vba within Excel (xp, win2000)

    Author
    Topic
    #366152

    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.

    Viewing 1 reply thread
    Author
    Replies
    • #566954

      Try something like this:

      Dim fs As New FileSystemObject
          fs.MoveFile "C:MyDirMyFile.txt", "C:MyDirOld"
      

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

    • #566957

      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

    Viewing 1 reply thread
    Reply To: Move files with vba within Excel (xp, win2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: