Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default moving files

How do I select all files in a folder and then have it ask me where to move
them too?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default 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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default 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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving files which are linked chrismc1972 Excel Discussion (Misc queries) 1 January 23rd 07 09:28 PM
Moving xls files that have links?? Bill Links and Linking in Excel 2 November 2nd 06 06:57 AM
Moving files JT Excel Programming 1 August 10th 06 04:02 PM
macro as and moving files dr chuck Excel Programming 1 June 30th 06 01:33 AM
Moving Files PraxisPete Excel Programming 3 December 1st 05 10:07 AM


All times are GMT +1. The time now is 06:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"