编译器错误调用私有子过程

时间:2013-07-29 15:08:08

标签: vba excel-vba excel

    Private Sub Workbook_SheetSelectionChange _
     (ByVal Sh As Object, ByVal Target As Excel.Range)
     x = Sh.UsedRange.Rows.Count
End Sub

我有一个这样的私有子程序,我试图通过

来调用它
 Workbook_SheetSelectionChange _

我得到一个编译错误,我试图重命名sub但它不允许我删除下划线,因为sub中的第二行。我想知道为什么会这样,我怎么称呼这个子?

2 个答案:

答案 0 :(得分:2)

_是一个续行字符

 Private Sub Workbook_SheetSelectionChange (ByVal Sh As Object, ByVal Target As Excel.Range)

相同
Private Sub Workbook_SheetSelectionChange _
 (ByVal Sh As Object, ByVal Target As Excel.Range)

与(极端)相同

Private _
Sub _
Workbook_SheetSelectionChange _
(ByVal _
Sh _
As _
Object, _
ByVal _
Target _
As _
Excel.Range)

答案 1 :(得分:1)

尝试简单:

Workbook_SheetSelectionChange

或者

Call Workbook_SheetSelectionChange

_是一个连续字符,是子程序名称的一部分。