由于运行时错误1004 VBA代码失败Microsoft Excel无法粘贴数据

时间:2017-07-17 09:29:36

标签: vba excel-vba excel

我收到运行时错误1004 Microsoft Excel无法粘贴数据 在以下代码中。我一直在运行复制和粘贴图片例程一段时间,突然Excel开始给我这个运行时错误。它已经工作了好几天,直到现在(没有操作系统更新或重新启动)。有人可以帮忙吗?

Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    r = "Business Mobile List - July 2017"
    Filename = Application.InputBox("Enter Filename:", "Business Mobile 
    FileName", r)
    If (Filename <> "") Then
    xlFile = "D:\try\big file vba\" & Filename
    Set XL = CreateObject("Excel.Application")
    Set wbk = XL.Workbooks.Open(xlFile)
    Application.CutCopyMode = False

         dateS = Format(Date, "dd/mm/yyyy")
        dateString = Application.InputBox("Enter A Date: (Format dd-mm-yyyy)", 
         dateS, dateS)
         TheDate = DateValue(dateString)

          With ActiveSheet
        LastRow = wbk.Sheets("Stuck orders").Cells(.Rows.Count, 
         "B").End(xlUp).Row
           End With


               For i = 2 To LastRow
              If (wbk.Sheets("Stuck orders").Cells(i, 19) = TheDate) Then
               wbk.Sheets("Stuck orders").Rows(i).EntireRow.Copy

               erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
               ActiveSheet.Cells(erow, 1).Select
               **ActiveSheet.Paste** 'error occured while pasting
               ActiveWorkbook.Save
              Application.CutCopyMode = False
                   End If

               Next i
          MsgBox "Fileuploaded"
           wbk.Save
            wbk.Close
           Application.CutCopyMode = False

                  Else
              MsgBox "File does not exist"
                End If
End Sub

0 个答案:

没有答案