vba - 将工作表传递给子例程

标签 vba excel

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

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. 声明wsPerformanceLeague作为工作表。 Dim wsPerformanceLeague as Worksheet

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

您必须使用单词Set

关于vba - 将工作表传递给子例程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38697715/

相关文章:

excel - 如何从 Excel VBA 释放进程内 COM Server 对象

vba - 增加 Excel PrintArea 的最大字符串长度

excel - 在一行中引用多个工作表

excel - 一旦条件在列中匹配,删除excel表中的行

java - 从特定列启动表 excel apache poi

vba - VBA 宏中的工作簿权限

excel - 将工作表复制到多个工作簿时更改引用

xml - 使用 R 将新数据附加到格式化的 xlsx 工作表

php - 将 XLSX 文件导入 MySQL 数据库

python - 使用python逐行从excel中提取图像