title: VBA copy paste all files in a folder
body: <p>My macro is running well since 2 months but now I need some help for another issue.
  We are running an controller on our server which is sending mails to our customer with attached pdf. Now this controller and my macro are running sometimes at the same time and when my macro is creating pdfs the controller wants to send it but is not able to do so because its already in creation.
  Now I thought the macro could save pdf into another folder and after that it will copy paste all files into the right folder for sending.</p>
  
  <p>My code is this:</p>
  
  <pre><code>Function Copy()
  
     Dim MyFile2 As Sting
     Dim myPath2 As String, myPath3 As String
  
     myPath2 = "L:\Host_Export\Pdf-Kundenmail\Test\"
     myPath3 = "L:\Host_Export\Pdf-Kundenmail\"
     MyFile2 = Dir(myPath2 &amp; "*.*")
     Do
          If MyFile2 = "" Then Exit Do
          FileCopy myPath2 &amp; MyFile2, myPath3 &amp; MyFile2
          End If
          myFile2 = Dir
      Loop
  
  End Function
  </code></pre>
  
  <p>But if I run it there is an error: <code>error on compilation  userdefined typ could not be defined.</code> like this: <a href="https://i0.wp.com/www.port135.com/wp-content/uploads/2012/08/error1-1.png" rel="nofollow noreferrer">https://i0.wp.com/www.port135.com/wp-content/uploads/2012/08/error1-1.png</a>.
  I alredy googled but don't get it how to set up or import something to fix this issue.</p>