Consulting

Results 1 to 4 of 4

Thread: Create backup of folder with date

  1. #1

    Create backup of folder with date

    Hey, looking to take a copy of a folder before I update it and save a copy of it under a different name. Used Ron De Bruins guide as a start but I'm getting a Runtime error 70, permission denied error on the second to last line, see my code below.


    Sub BackupOwnershipFiles()'This example move the folder from FromPath to ToPath.
        
        If MsgBox("Are you sure you'd like to create a back up of the ownership files?", vbYesNo) = vbNo Then
        Exit Sub
        Else
        End If
        
        
        Dim FSO As Object
        Dim FromPath As String
        Dim ToPath As String
        
        yyyy = Year(Now)
        mm = Format(Month(Now), "00")
        dd = Format(Day(Now), "00")
    
    
        FromPath = "S:\Regional Planners Product Ownership\Manager_Ownership_Files_"  '<< Change
        ToPath = "C:\Users\name\Documents\Manager Ownership Backups\" & mm & "_" & dd & "_" & yyyy    '<< Change
        'Note: It is not possible to use a folder that exist in ToPath
    
    
        If Right(FromPath, 1) = "\" Then
            FromPath = Left(FromPath, Len(FromPath) - 1)
        End If
    
    
        If Right(ToPath, 1) = "\" Then
            ToPath = Left(ToPath, Len(ToPath) - 1)
        End If
    
    
        Set FSO = CreateObject("scripting.filesystemobject")
    
    
        If FSO.FolderExists(FromPath) = False Then
            MsgBox FromPath & " doesn't exist"
            Exit Sub
        End If
    
    
        If FSO.FolderExists(ToPath) = True Then
            MsgBox ToPath & " exist, not possible to move to a existing folder"
            Exit Sub
        End If
    
    
        FSO.MoveFolder Source:=FromPath, Destination:=ToPath 'THIS IS WHERE THE ERROR IS
        MsgBox "The folder is moved from " & FromPath & " to " & ToPath
    
    
    End Sub

  2. #2
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    Try copying the source folder to the destination folder, and then delete the source folder.

    Artik

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Maybe
    FSO.MoveFolder FromPath, ToPath
    Last edited by SamT; 03-16-2020 at 12:42 AM.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    Thank you for the input! I tracked it down to a permissions issue within SharePoint.

    My goal was just to copy the folder as a backup so I changed

    FSO.MoveFolder
    To
    FSO.CopyFolder
    And it works great! Thank you for the inputs, sorry for the dumb question.

Posting Permissions

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