运行时错误1004应用程序定义的或对象定义的错误

时间:2016-02-22 07:07:58

标签: excel excel-vba vba

我在工作伙伴的帮助下创建了一个宏,这个宏的对象是打开保存的日志文件将内容复制到工作表中,关闭表单然后重新开始。我有超过一千个文件要导入到我编写的数据库中但无法导入它们,因为表单布局布局不是很好。到目前为止它工作约30%,然后得到运行时错误。我尝试选择较少的文件,但仍然只有30%左右。这是代码。

Sub PopulateData2()

    Dim wbName As String
    Dim wbPath As String
    Dim wsName As String
    Dim cellRef As String
    Dim calcState As Long

    calcState = Application.Calculation

    i = 2

    Do Until Sheet3.Cells(i, 2) = ""
    wbPath = Sheet3.Cells(i, 2)
    wbName = Sheet3.Cells(i, 1)
    wsName = "Sheet1"


        cellRef = Range("a1", "i31").Address

        Dim arg As String
        arg = "='" & wbPath & "[" & wbName & "]" & wsName & "'!" &cellRef 'Range(cellRef).Address(True, True, xlR1C1)

        Application.Calculation = xlCalculationAutomatic
        'Application.DisplayAlerts = False
        Sheet1.Range("a1", "i31").Value = arg
        Sheet1.Range("a1", "i31").Value = Sheet1.Range("a1", "i31").Value 'essentially a paste/values over the formula.
        'Application.DisplayAlerts = True
        'Application.Calculation = calcState
        Button1_Click


    i = i + 1


    Loop

End Sub

Sub Button1_Click()
    'Application.ScreenUpdating = False
    'Sheet2.Range("b3:bc3").Select
    'Selection.Copy
    rn = Sheet2.Range("b2:bc3").End(xlDown).Offset(1, 0).Row

    i = 0
    Do Until Sheet2.Cells(2, 2 + i) = ""
        Sheet2.Cells(rn, 2 + i) = Sheet2.Cells(3, 2 + i).Value
        i = i + 1
    Loop

    'Selection.Offset(1, 0).Select
    'Selection.PasteSpecial xlPasteValues
    'Sheet2.Range("a1").Select

    'Application.ScreenUpdating = True

End Sub

0 个答案:

没有答案