Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default Copy a file into multiple dub-folders

Hi. I have a folder called Data, with several subfolders inside it. The
number of subfolders and the name of each subfolder will vary over time. I
need to copy a template file (on a KNOWN folder) into each subfolder under
data. Can this be automated with VBA?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy a file into multiple dub-folders


Plagerized from Excel VBA Help:

Code
-------------------
Sub Test()

Dim MyName As String
Dim MyPath As String
MyPath = "C:\Data\"

MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName < "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName < "." And MyName < ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
FileCopy "C:\Data\YourFile.ext", "C:\Data\" & MyName & "\YourFile.ext"
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop

End Su
-------------------

I've not used the FileCopy method, but it looks to work. You may wan
to change it to read Debug.Print "C:\Data\YourFile.ext", "C:\Data\"
MyName & "\YourFile.ext" to start with to see where things are copied.



--
kkkni
-----------------------------------------------------------------------
kkknie's Profile: http://www.excelforum.com/member.php...nfo&userid=754
View this thread: http://www.excelforum.com/showthread.php?threadid=26523

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy a file into multiple dub-folders

Look at the Excel VBA example for the Dir command. This can help you
identify the folders in a directory.

--
Regards,
Tom Ogilvy


"Steph" wrote in message
...
Hi. I have a folder called Data, with several subfolders inside it. The
number of subfolders and the name of each subfolder will vary over time.

I
need to copy a template file (on a KNOWN folder) into each subfolder under
data. Can this be automated with VBA?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default Copy a file into multiple dub-folders

Thanks guys!

"Tom Ogilvy" wrote in message
...
Look at the Excel VBA example for the Dir command. This can help you
identify the folders in a directory.

--
Regards,
Tom Ogilvy


"Steph" wrote in message
...
Hi. I have a folder called Data, with several subfolders inside it.

The
number of subfolders and the name of each subfolder will vary over time.

I
need to copy a template file (on a KNOWN folder) into each subfolder

under
data. Can this be automated with VBA?






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
copy and pasting one file into several different folders james Excel Discussion (Misc queries) 2 May 12th 10 04:31 PM
copy workbook into multiple folders MIke Excel Discussion (Misc queries) 5 October 26th 07 04:40 PM
how to open a file with a same name but in different folders excelbuff Excel Discussion (Misc queries) 1 January 31st 07 09:27 PM
opening multiple .txt files from multiple folders Corben Excel Discussion (Misc queries) 3 March 16th 06 12:43 AM
Help on file and folders Please Aliandro Excel Programming 1 April 28th 04 10:29 AM


All times are GMT +1. The time now is 03:41 PM.

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"