将工作表传递给子例程

时间:2016-08-01 11:29:15

标签: excel vba excel-vba

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

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)

1 个答案:

答案 0 :(得分:3)

  1. wsPerformanceLeague声明为工作表。 Dim wsPerformanceLeague as Worksheet

  2. wsPerformanceLeague = Worksheets("PerformanceLeague")更改为Set wsPerformanceLeague = Worksheets("PerformanceLeague")

  3. 您必须使用Set

    这个词