title: Why does "Paste Method of Worksheet class failed" occasionally occur?
body: <p>Some context: the following macro opens the most recent file in the specified directory.  I am trying to copy all the data in the newly opened sheet into another worksheet.  Sometimes, and only <em>sometimes</em>, I receive a 1004 error.  </p>
  
  <blockquote>
    <p>"Paste method of Worksheet class failed".  </p>
  </blockquote>
  
  <p>Sometimes the macro works. I cannot pinpoint why this happens.</p>
  
  <p>Can anyone identify issues with the code?
  Clearing the clipboard works sometimes, but not always.
  Also, I have been using several macros just like this one (linked to different folders) in a larger macro.  I run into the same problem occasionally.</p>
  
  <pre><code>Sub ImportOldRates()
  
      'Declare the variables
      Dim MyPath As String
      Dim MyFile As String
      Dim LatestFile As String
      Dim LatestDate As Date
      Dim LMD As Date
  
      'Specify the path to the folder
      MyPath = "C:\Folder1\Folder2\"
  
      'Make sure that the path ends in a backslash
      If Right(MyPath, 1) &lt;&gt; "\" Then MyPath = MyPath &amp; "\"
  
      'Get the first Excel file from the folder
      MyFile = Dir(MyPath &amp; "*.xls", vbNormal)
  
      'If no files were found, exit the sub
      If Len(MyFile) = 0 Then
          MsgBox "No files were found...", vbExclamation
          Exit Sub
      End If
  
      'Loop through each Excel file in the folder
      Do While Len(MyFile) &gt; 0
  
          'Assign the date/time of the current file to a variable
          LMD = FileDateTime(MyPath &amp; MyFile)
  
          'If the date/time of the current file is greater than the latest
          'recorded date, assign its filename and date/time to variables
          If LMD &gt; LatestDate Then
              LatestFile = MyFile
              LatestDate = LMD
          End If
  
          'Get the next Excel file from the folder
          MyFile = Dir
  
      Loop
  
      'Open the latest file
      Workbooks.Open MyPath &amp; LatestFile
      Application.DisplayAlerts = False
      Application.EnableEvents = False
      Application.Run "ConnectChartEvents"
      Cells.Select
      Range("E2").Activate
      Selection.copy
      ActiveWindow.Close
      ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
      DisplayAsIcon:=False, NoHTMLFormatting:=True
      Application.CutCopyMode = False
      Selection.Columns.AutoFit
      Range("A1").Select
      Application.DisplayAlerts = True
      Application.EnableEvents = True
  
  End Sub
  </code></pre>