Backing up my folders

  • Thread starter Thread starter Greg B
  • Start date Start date
G

Greg B

Hi all,

Just wondering how I can back up a complete directory folder containing all
the .xls files I have. I have setup a macro that save certain file and back
them up but I would like to have the complete file copied and saved into
I:\backup\with today's date as the folder name.

Is there anyway to do this?

Thanks

Greg
 
Greg, you could try this.

Sub Archive(YourDir As String)
Dim ArchiveDir As String
Dim thisFile As String

'Create the archive Directory
ArchiveDir = "I:\Backup\" & Format(Date, "dd-mm-yyyy")
If Dir(ArchiveDir, vbDirectory) = "" Then MkDir ArchiveDir

'Copy the files
thisFile = Dir(YourDir & "\*.xls")
While thisFile <> ""
FileCopy YourDir & thisFile, ArchiveDir & "\" & thisFile
thisFile = Dir
Wend
End Sub

Good luck,
Fred
 
Greg,

The ubiquitous FileSystemObject is one way

'---------------------------------------------------------------------------
Sub CopyFolder()
'---------------------------------------------------------------------------
Dim oFSO As Object
Dim sFolder As String

Set oFSO = CreateObject("Scripting.FileSystemObject")
sFolder = "I:\Backup\"
If Not oFSO.FolderExists(sFolder) Then
MkDir sFolder
End If
If Not oFSO.FolderExists(sFolder & Format(Date, "yyyy-mm-dd")) Then
MkDir sFolder & Format(Date, "yyyy-mm-dd")
End If
oFSO.CopyFolder "C:\myTest\*", sFolder & "\"
Set oFSO = Nothing
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top