create folder/copy file to folder

  • Thread starter Thread starter Dorian C. Chalom
  • Start date Start date
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!
 
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.
 
Back
Top