Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBA to copy and paste folder

I need help with some code to copy a folder from one destination and paste it
to another.

Sub Transfer()

Dim copy_dir As String
Dim paste_dir As String

copy_dir = "C:\test_source"
paste_dir = "C:\test_destination"

FileCopy copy_dir, paste_dir

It seems that filecopy is not the answer, I need something like foldercopy.
Is there a VBA command to copy and paste folders and contents similr to
filecopy?

Thanks
Ronaldo
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default VBA to copy and paste folder

Try the following:

FileSystemObject.CopyFolder copy_dir, paste_dir

Regards,

Alasdair Stirling

"Ronaldo" wrote:

I need help with some code to copy a folder from one destination and paste it
to another.

Sub Transfer()

Dim copy_dir As String
Dim paste_dir As String

copy_dir = "C:\test_source"
paste_dir = "C:\test_destination"

FileCopy copy_dir, paste_dir

It seems that filecopy is not the answer, I need something like foldercopy.
Is there a VBA command to copy and paste folders and contents similr to
filecopy?

Thanks
Ronaldo

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBA to copy and paste folder

Alastair,

Tried using FileSystemObject.CopyFolder copy_dir, paste_dir but gor run time
424 error - object required - do I need to declare something??

Thanks

Ronaldo


"Alasdair Stirling" wrote:

Try the following:

FileSystemObject.CopyFolder copy_dir, paste_dir

Regards,

Alasdair Stirling

"Ronaldo" wrote:

I need help with some code to copy a folder from one destination and paste it
to another.

Sub Transfer()

Dim copy_dir As String
Dim paste_dir As String

copy_dir = "C:\test_source"
paste_dir = "C:\test_destination"

FileCopy copy_dir, paste_dir

It seems that filecopy is not the answer, I need something like foldercopy.
Is there a VBA command to copy and paste folders and contents similr to
filecopy?

Thanks
Ronaldo

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA to copy and paste folder

Dim fso as Object
set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFolder copy_dir, paste_dir

--
Regards,
Tom Ogilvy



"Ronaldo" wrote in message
...
Alastair,

Tried using FileSystemObject.CopyFolder copy_dir, paste_dir but gor run

time
424 error - object required - do I need to declare something??

Thanks

Ronaldo


"Alasdair Stirling" wrote:

Try the following:

FileSystemObject.CopyFolder copy_dir, paste_dir

Regards,

Alasdair Stirling

"Ronaldo" wrote:

I need help with some code to copy a folder from one destination and

paste it
to another.

Sub Transfer()

Dim copy_dir As String
Dim paste_dir As String

copy_dir = "C:\test_source"
paste_dir = "C:\test_destination"

FileCopy copy_dir, paste_dir

It seems that filecopy is not the answer, I need something like

foldercopy.
Is there a VBA command to copy and paste folders and contents similr

to
filecopy?

Thanks
Ronaldo



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default VBA to copy and paste folder

To use the FileSystemObject, you need to set a reference (VBA,
Tools menu, References) to the "Microsoft Scripting Runtime"
library. Then, declare a variable with a FileSystemObject type,
and use that variable.

Dim FSO As Scripting.FileSystemObject
FSO.CopyFolder old_folder, new_folder, True



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Ronaldo" wrote in message
...
Alastair,

Tried using FileSystemObject.CopyFolder copy_dir, paste_dir but
gor run time
424 error - object required - do I need to declare something??

Thanks

Ronaldo


"Alasdair Stirling" wrote:

Try the following:

FileSystemObject.CopyFolder copy_dir, paste_dir

Regards,

Alasdair Stirling

"Ronaldo" wrote:

I need help with some code to copy a folder from one
destination and paste it
to another.

Sub Transfer()

Dim copy_dir As String
Dim paste_dir As String

copy_dir = "C:\test_source"
paste_dir = "C:\test_destination"

FileCopy copy_dir, paste_dir

It seems that filecopy is not the answer, I need something
like foldercopy.
Is there a VBA command to copy and paste folders and
contents similr to
filecopy?

Thanks
Ronaldo





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default VBA to copy and paste folder

I forgot the line of code to create the FSO.

Dim FSO As Scripting.FileSystemObject
Set FSO = New Scripting.FileSystemObject
FSO.CopyFolder old_folder, new_folder, True


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chip Pearson" wrote in message
...
To use the FileSystemObject, you need to set a reference (VBA,
Tools menu, References) to the "Microsoft Scripting Runtime"
library. Then, declare a variable with a FileSystemObject type,
and use that variable.

Dim FSO As Scripting.FileSystemObject
FSO.CopyFolder old_folder, new_folder, True



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Ronaldo" wrote in message
...
Alastair,

Tried using FileSystemObject.CopyFolder copy_dir, paste_dir
but gor run time
424 error - object required - do I need to declare something??

Thanks

Ronaldo


"Alasdair Stirling" wrote:

Try the following:

FileSystemObject.CopyFolder copy_dir, paste_dir

Regards,

Alasdair Stirling

"Ronaldo" wrote:

I need help with some code to copy a folder from one
destination and paste it
to another.

Sub Transfer()

Dim copy_dir As String
Dim paste_dir As String

copy_dir = "C:\test_source"
paste_dir = "C:\test_destination"

FileCopy copy_dir, paste_dir

It seems that filecopy is not the answer, I need something
like foldercopy.
Is there a VBA command to copy and paste folders and
contents similr to
filecopy?

Thanks
Ronaldo





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA to copy and paste folder

Just some added explanation because of Chip's response.
My method uses late binding and doesn't require the reference as Chip has
stated. His method (early binding) would be faster since creating the
reference provides more information to Excel VBA.

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
Dim fso as Object
set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFolder copy_dir, paste_dir

--
Regards,
Tom Ogilvy



"Ronaldo" wrote in message
...
Alastair,

Tried using FileSystemObject.CopyFolder copy_dir, paste_dir but gor run

time
424 error - object required - do I need to declare something??

Thanks

Ronaldo


"Alasdair Stirling" wrote:

Try the following:

FileSystemObject.CopyFolder copy_dir, paste_dir

Regards,

Alasdair Stirling

"Ronaldo" wrote:

I need help with some code to copy a folder from one destination and

paste it
to another.

Sub Transfer()

Dim copy_dir As String
Dim paste_dir As String

copy_dir = "C:\test_source"
paste_dir = "C:\test_destination"

FileCopy copy_dir, paste_dir

It seems that filecopy is not the answer, I need something like

foldercopy.
Is there a VBA command to copy and paste folders and contents similr

to
filecopy?

Thanks
Ronaldo





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 do I paste a set of folder NAMES into a set of cells? No Name Excel Discussion (Misc queries) 0 September 13th 07 08:56 AM
How do I paste a set of folder NAMES into a set of cells? Jedi Leba Excel Discussion (Misc queries) 2 September 13th 07 08:54 AM
Copy a folder in VB Brettjg Excel Discussion (Misc queries) 2 March 12th 07 02:34 PM
Excel cut/Paste Problem: Year changes after data is copy and paste Asif Excel Discussion (Misc queries) 2 December 9th 05 05:16 PM
Create Folder / Copy Folder / Replace Murray Outtrim[_2_] Excel Programming 0 February 24th 04 06:40 PM


All times are GMT +1. The time now is 05:25 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"