Hello, I'm trying to write code allowing me to Copy a folder then paste it. I have the basic code down using fso.CopyFolder. Instead of using a set destination I would like to prompt the user to select the destination folder. Thanks for the help!
Copy Folder
- Markus1989
- Thread is marked as Resolved.
-
-
This code allows you to browse for a folder
Code
Display MoreSub SelectFolder() Dim sFolder As String ' '/// Open the select folder dialog With Application.FileDialog(msoFileDialogFolderPicker) If .Show = -1 Then ' if OK is pressed sFolder = .SelectedItems(1) End If End With If sFolder <> "" Then ' if a file was chosen ' ********************* ''/// put your code in here ' ********************* End If End Sub
-
Thanks for that. But, is there a way to prompt a SaveAs window to open? I'm copying the same folder each time so I can have that path stored in my code. Its the destination that's variable. So I have my code attached to a button. I would like to click it then be prompted to select a destination location and change the folder name using a SaveAs. The folder contains a number of empty sub folders that represent a folder hierarchy that I use often.
-
Savas works with files, I think this might be useful. You should be able to incorporate the browse code to get the to address.
-
I'm still struggling to find the code I need. So, I have code to copy the folder hierarchy and store it in the users temp folder. Is there a way to then have a SaveAs window automatically open after the macro stores the folder in temp? As if I am right clicking on the folder in temp and selecting save as? So the user can then save the folder where they want? Sample of my code below.
Code
Display MoreSub Copy_Folder() Dim FSO As Object Dim FromPath As String Dim ToPath As String Dim username As String username = Environ("username") FromPath = "C:\" ToPath = "C:\Temp\1\" 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 'Open SaveAs window to save the copied folder in temp to a selected location.
-
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!