![]() |
moving files
How do I select all files in a folder and then have it ask me where to move
them too? |
moving files
Donna,
Here's one way: Sub test() Dim strSource As String Dim strDest As String Dim strFileName As String strSource = InputBox("Enter source folder path") strDest = InputBox("Enter destination folder path") strFileName = Dir(strSource, vbDirectory) If strFileName = "" Then MsgBox "Source Folder path is invalid", vbCritical Exit Sub End If strFileName = Dir(strDest, vbDirectory) If strFileName = "" Then MsgBox "Destination Folder path is invalid", vbCritical Exit Sub End If strFileName = Dir(strSource & "\*.*") While strFileName < "" Name strSource & "\" & strFileName As strDest & "\" & strFileName strFileName = Dir Wend End Sub -- Hope that helps. Vergel Adriano "Donna S" wrote: How do I select all files in a folder and then have it ask me where to move them too? |
moving files
"Donna S" wrote:
How do I select all files in a folder and then have it ask me where to move them too? You can also use the FileSystemObject object: Sub test() Set fso = CreateObject("Scripting.FileSystemObject") strSource = InputBox("Enter source folder path") strDest = InputBox("Enter destination folder path") If Not fso.FolderExists(strSource) Then MsgBox "Source Folder path is invalid", vbCritical End If If Not fso.FolderExists(strDest) Then MsgBox "Target Folder path is invalid", vbCritical End If If Right(strDest, 1) < "\" Then strDest = strDest & "\" End If For Each file In fso.GetFolder(strSource).Files file.Move strDest Next End Sub Hope this is of some help. -- urkec |
moving files
Vergel,
Can you help me change the macro so it doesn't ask me the source destination because my source destination will always be the same. We can call the source destination F:\Daily. I hope you can help. Thanks, Donna "Vergel Adriano" wrote: Donna, Here's one way: Sub test() Dim strSource As String Dim strDest As String Dim strFileName As String strSource = InputBox("Enter source folder path") strDest = InputBox("Enter destination folder path") strFileName = Dir(strSource, vbDirectory) If strFileName = "" Then MsgBox "Source Folder path is invalid", vbCritical Exit Sub End If strFileName = Dir(strDest, vbDirectory) If strFileName = "" Then MsgBox "Destination Folder path is invalid", vbCritical Exit Sub End If strFileName = Dir(strSource & "\*.*") While strFileName < "" Name strSource & "\" & strFileName As strDest & "\" & strFileName strFileName = Dir Wend End Sub -- Hope that helps. Vergel Adriano "Donna S" wrote: How do I select all files in a folder and then have it ask me where to move them too? |
All times are GMT +1. The time now is 12:34 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com