PDA

View Full Version : Creating a folder with cell contents



appc777
04-09-2011, 09:03 PM
I would like to
1-create folder its name is the cell B8 + E4 value + today date
2- if the folder exists overwrites
3-copy all files to that folder from another folder its name is datafiles
4-if there is no files in datafiles return (no files copied)

shrivallabha
04-10-2011, 12:05 AM
Welcome to VBAX.

Have a look at this thread which probably does a task similar to what you are setting out to do in Step 3.
http://www.vbaexpress.com/forum/showthread.php?t=36352

If you know a bit of VBA then the first part can be achieved by using FileSystemObject like:
Sub CreateFolder()
Dim objFSO As Object
Dim sPath As String
On Error GoTo ErrorHandler
Set objFSO = CreateObject("Scripting.FileSystemObject")
sPath = Range("B8").Value & "\" & Range("E4").Value & "\" & Date$
objFSO.CreateFolder (sPath)
ErrorHandler:
If Err.Number <> 0 Then
Select Case Err.Number
Case 58
MsgBox "The Specified Folder Already Exists!"
Case Else
MsgBox Err.Description
End Select
End If
End Sub