moving files

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I select all files in a folder and then have it ask me where to move
them too?
 
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
 
Donna S said:
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.
 
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
 

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