locked
How to use FSO RRS feed

  • Question

  • Hello,

    I try to move Folder "Data1" into another Folder "Test" , but I get error that ToPath folder exist , what mean that ?

    ich just want to move folder (Data1) into folder (Test) , can anyone help please ?

    Sub Move_Folder()
    
        Dim FSO As Object
        Dim FromPath As String
        Dim ToPath As String
    
        FromPath = "C:\Users\Tim\Data1"  
        ToPath = "C:\Users\Tim\Test" 
    
        FSO.MoveFolder Source:=FromPath, Destination:=ToPath
        
    	MsgBox "The folder is moved from " & FromPath & " to " & ToPath
    
    End Sub

     

    Tuesday, June 5, 2018 11:29 AM

Answers

  • To make it clear that you want to move the Data1 folder into the Test folder, use

        ToPath = "C:\Users\Tim\Test\"

    with a backslash at the end, or specify the full destination path:

        ToPath = "C:\Users\Tim\Test\Data1"

    (and surely you need a line Set FSO = CreateObject("Scripting.FileSystemObject") to make this work?)


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Req_En Wednesday, June 6, 2018 8:06 AM
    Tuesday, June 5, 2018 12:03 PM

All replies

  • To make it clear that you want to move the Data1 folder into the Test folder, use

        ToPath = "C:\Users\Tim\Test\"

    with a backslash at the end, or specify the full destination path:

        ToPath = "C:\Users\Tim\Test\Data1"

    (and surely you need a line Set FSO = CreateObject("Scripting.FileSystemObject") to make this work?)


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Req_En Wednesday, June 6, 2018 8:06 AM
    Tuesday, June 5, 2018 12:03 PM
  • Hello Hans ,

    thank u it works perfectly with backslash , but aktually my path is in cell , can i call the path from cell , I try this code but it does not work ?

    Sub Move_Folder()
    
        
        Dim FSO As Object
        Dim FromPath As String
        Dim ToPath As String
    
    	FromPath = sheet1.Cells(3,4)
    	ToPath = sheet1.Cells(ActiveRow,15)	
    	
        Set FSO = CreateObject("Scripting.FileSystemObject")
    
        
        FSO.MoveFolder Source:=FromPath, Destination:=ToPath
        MsgBox "The folder is moved from " & FromPath & " to " & ToPath
    
    End Sub
    

    Best regards,

    Neven



    • Edited by Req_En Tuesday, June 5, 2018 2:08 PM
    Tuesday, June 5, 2018 2:06 PM
  • Use

     ToPath = sheet1.Cells(ActiveRow,15) & "\"


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Tuesday, June 5, 2018 3:41 PM
  • Thank u very much

    Best regards,

    Neven

    Wednesday, June 6, 2018 8:05 AM