move files from one folder to another

前端 未结 5 916
广开言路
广开言路 2020-12-18 07:27

actually I am searching for code to move excel files from one folder to another if there is any way to do so Please someone help me. I am very sorry but I dont know how to d

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-18 08:21

    Sub move_data()
        'Move test data to folder
    
        Dim FSO As Object
        Dim FromPath As String
        Dim ToPath As String
        Dim Fdate As Date
        Dim FileInFromFolder As Object
    
    
        MkDir "D:\TEST\"        'Create new folder name TEST in D:
        FromPath = "E:\test\"   'Source files
        ToPath = "D:\TEST\"     'Target destination
    
        Set FSO = CreateObject("scripting.filesystemobject")
    
        If FSO.FolderExists(FromPath) = False Then
            MsgBox FromPath & " doesn't exist"
            Exit Sub
        End If
    
        For Each FileInFromFolder In FSO.getfolder(FromPath).Files
            FileInFromFolder.move ToPath
        Next FileInFromFolder
    
    End Sub
    

提交回复
热议问题