首页 > 解决方案 > 宏不起作用:“编译错误:不支持对象库功能”

问题描述

每当我运行这个宏时,我都会得到:

编译错误:“不支持对象库功能”并突出显示“设置 ws1 =”。

发生了什么?有什么问题吗?

谢谢

Sub Airpush()
'Define your variables.
Dim ws1 As Worksheet, ws2 As Worksheet, cel As Range, i As Long

'Assign your worksheet variables.
Set ws1 = ThisWorkbook.Sheets("CAMPAIGN_PLANNER")
Set ws2 = ThisWorkbook.Sheets("REPORT_DOWNLOAD")

    'First loop through each cell in Sheet2, Column E, (start at row 2 to account
    'for header row) to get the value to find in Sheet1, Column C.
    For Each cel In ws2.Range("A2:A" & ws2.Range("A" & ws2.Rows.Count).End(xlUp).Row)

        'Then loop through each cell in Sheet1, column C. If you get a match, then
        'copy the value from Sheet2, column B, cel.row to Sheet1, Column S, i row.
        For i = 2 To ws1.Range("L" & ws1.Rows.Count).End(xlUp).Row

            If cel.Value = ws1.Cells(i, 3).Value Then
                ws1.Cells(i, 3).Offset(, 16).Value = cel.Offset(, 3).Value
                ws1.Cells(i, 3).Offset(, 15).Value = cel.Offset(, 4).Value
                ws1.Cells(i, 3).Offset(, 17).Value = cel.Offset(, 2).Value
            End If

        Next i 'loops through every used cell in Column C for all matches
    Next cel 'loop to the next cell in Sheets2, Columns E

End Sub

标签: excelvba

解决方案


我不确定问题出在哪里,但是当我在激活的版本上重新打开 excel 时,宏工作正常,这表明问题与只读版本有关。

感谢所有评论的人!


推荐阅读