I grabbed some VBA online and made a few small edits. The VBA copies a specified folder and allows me to rename and save. Problem is if I click cancel on the dialog box it still saves as a "FALSE". I need it to not overwrite an existing file and also exit the sub if cancel is clicked.
Sorry, a little new and still learning. Any help would be greatly appreciated!
Sub Copy_Folder()
'This example copy all files and subfolders from FromPath to ToPath.
'Note: If ToPath already exist it will overwrite existing files in this folder
'if ToPath not exist it will be made for you.
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
MsgBox "CREATE NEW CUSTOMER FILE"
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "cmd /c mkdir C:\Dropbox\JESSE TESTING" & UserName
FromPath = "C:\Dropbox\CUSTOMER TEMPLATE FOLDER" '<< Change
ToPath = Application.GetSaveAsFilename
'If you want to create a backup of your folder every time you run this macro
'you can create a unique folder with a Date/Time stamp.
'ToPath = "C:\Users\Ron\" & Format(Now, "yyyy-mm-dd h-mm-ss")
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
FSO.CopyFolder Source:=FromPath, Destination:=ToPath
MsgBox "CUSTOMER TEMPLATE HAS BEEN COPIED AND SAVED AS YOUR NEW CUSTOMER"
End Sub
Bookmarks