Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Copy Files to other folder

I want to copy a number of files from one folder to another
The code that I am trying to use is:
Dim WbSource As Workbook
Set WbSource.Path = "C:\Mis documentos\10 October 2005"
For Each Workbook In WbSource.Path
Workbook.Copy "C:\Mis documentos\12 December 2005"
Next Workbook
However it tells me that I am making wrong use of Path
Can someone help?
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Copy Files to other folder

This may help get you started. It should copy all .xls files.

Sub test()
Const Source = "C:\Mis documentos\10 October 2005\*.xls"
Const Dest = "C:\Mis documentos\12 December 2005"
Dim FSO As Object

Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.folderexists(Dest) Then MkDir Dest
FSO.copyfile Source, Dest
End Sub





"TISR" wrote:

I want to copy a number of files from one folder to another
The code that I am trying to use is:
Dim WbSource As Workbook
Set WbSource.Path = "C:\Mis documentos\10 October 2005"
For Each Workbook In WbSource.Path
Workbook.Copy "C:\Mis documentos\12 December 2005"
Next Workbook
However it tells me that I am making wrong use of Path
Can someone help?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Copy Files to other folder

A Set statement is used for objects only.
Path is a String, so "Set WbSource.Path = " will cause an error.
For moving files/folders I prefer using the Scripting Runtime FileSystemObject.
When you use a wild card "*", all files of the particular type are moved.
The following code copies all .xls files from one folder to another.
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

'------------------------
Sub CopyFilesWithScriptingRuntime()
Dim strFromPath As String
Dim strToPath As String
Dim Fso As Object

'The * can only be used in the last position.
strFromPath = "C:\Mis documentos\10 October 2005\*.xls"
'The * cannot be used in the destination path.
strToPath = "C:\Mis documentos\12 December 2005"

Set Fso = CreateObject("Scripting.FileSystemObject")

'Copy all of the .xls files - False prevents overwriting of files
Fso.CopyFile strFromPath, strToPath, False
Set Fso = Nothing
End Sub
'--------------------


"TISR"
wrote in message
...
I want to copy a number of files from one folder to another
The code that I am trying to use is:
Dim WbSource As Workbook
Set WbSource.Path = "C:\Mis documentos\10 October 2005"
For Each Workbook In WbSource.Path
Workbook.Copy "C:\Mis documentos\12 December 2005"
Next Workbook
However it tells me that I am making wrong use of Path
Can someone help?
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Copy Files to other folder

Many Thanks For The scripting.FileSystemObject
Regards
"JMB" wrote:

This may help get you started. It should copy all .xls files.

Sub test()
Const Source = "C:\Mis documentos\10 October 2005\*.xls"
Const Dest = "C:\Mis documentos\12 December 2005"
Dim FSO As Object

Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.folderexists(Dest) Then MkDir Dest
FSO.copyfile Source, Dest
End Sub





"TISR" wrote:

I want to copy a number of files from one folder to another
The code that I am trying to use is:
Dim WbSource As Workbook
Set WbSource.Path = "C:\Mis documentos\10 October 2005"
For Each Workbook In WbSource.Path
Workbook.Copy "C:\Mis documentos\12 December 2005"
Next Workbook
However it tells me that I am making wrong use of Path
Can someone help?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Copy Files to other folder

Many Thanks for Scripting.FileSystemObject
Regards

"Jim Cone" wrote:

A Set statement is used for objects only.
Path is a String, so "Set WbSource.Path = " will cause an error.
For moving files/folders I prefer using the Scripting Runtime FileSystemObject.
When you use a wild card "*", all files of the particular type are moved.
The following code copies all .xls files from one folder to another.
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

'------------------------
Sub CopyFilesWithScriptingRuntime()
Dim strFromPath As String
Dim strToPath As String
Dim Fso As Object

'The * can only be used in the last position.
strFromPath = "C:\Mis documentos\10 October 2005\*.xls"
'The * cannot be used in the destination path.
strToPath = "C:\Mis documentos\12 December 2005"

Set Fso = CreateObject("Scripting.FileSystemObject")

'Copy all of the .xls files - False prevents overwriting of files
Fso.CopyFile strFromPath, strToPath, False
Set Fso = Nothing
End Sub
'--------------------


"TISR"
wrote in message
...
I want to copy a number of files from one folder to another
The code that I am trying to use is:
Dim WbSource As Workbook
Set WbSource.Path = "C:\Mis documentos\10 October 2005"
For Each Workbook In WbSource.Path
Workbook.Copy "C:\Mis documentos\12 December 2005"
Next Workbook
However it tells me that I am making wrong use of Path
Can someone help?

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
How to copy 30 csv files from a folder to another folder ddiicc Excel Programming 1 July 17th 05 09:42 AM
Copy files from spreadsheet into folder Intotao Excel Discussion (Misc queries) 3 January 27th 05 11:38 PM
Copy several range from all files in folder into several worksheets Adri[_2_] Excel Programming 13 June 27th 04 03:52 PM
Copy same data from all files in folder BENNY Excel Programming 1 June 18th 04 10:52 PM
Copy Files from a folder to new location saybut[_3_] Excel Programming 0 February 10th 04 03:26 PM


All times are GMT +1. The time now is 09:46 AM.

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

About Us

"It's about Microsoft Excel"