ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy a file into multiple dub-folders (https://www.excelbanter.com/excel-programming/312076-copy-file-into-multiple-dub-folders.html)

Steph[_3_]

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?



kkknie[_186_]

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


Tom Ogilvy

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?





Steph[_3_]

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?








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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com