Copy a file into multiple dub-folders

S

Steph

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?
 
K

kkknie

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
 
T

Tom Ogilvy

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top