create folder/copy file to folder

D

Dorian C. Chalom

How would I go about checking to see if a folder exist and if it doesn't
create it then copy a file to that folder?

Thanks as always....you are the best!
 
D

Douglas J. Steele

Dim strDestFolder As String
Dim strSrceFolder As String

strDestFolder = "C:\Folder"
strSrceFolder = "C:\Other Folder"

If Len(Dir(strDestFolder, vbDirectory)) = 0 Then
' Folder does not exist
MkDir strDestFolder
End If

FileCopy strSrceFolder & "\File.txt", strDestFolder & "\File.txt"

Note that you cannot create multiple levels of folders at once. For example,
if you wanted C:\Folder1\Folder2, but C:\Folder1 doesn't already exist, you
must create C:\Folder1 before you can create C:\Folder1\Folder2.
 

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