我试图通过传递某个工作表名称作为参数来调用子例程,但收到以下错误:

Object doesn't support this property or method


这是我的代码:

Public Sub PerformanceLeague()

Dim wsPerformanceLeague As Worksheet

Set wsPerformanceLeague = Worksheets("PerformanceLeague")
SetHeadings wsPerformanceLeague

End Sub

Public Sub SetHeadings(sSheet As Worksheet)

Dim headers() As Variant
Dim ws As Worksheet
Dim wb As Workbook

Application.ScreenUpdating = False

End Sub


我也尝试过如下调用子例程,但是收到相同的错误:

Call SetHeadings(wsPerformanceLeague)

最佳答案

wsPerformanceLeague声明为工作表。 Dim wsPerformanceLeague as Worksheet
wsPerformanceLeague = Worksheets("PerformanceLeague")更改为Set wsPerformanceLeague = Worksheets("PerformanceLeague")


您必须使用Set一词

10-04 15:45