在用户表单Excel VBA中调用公用子程序

我最近开始学习excel vba,目前我坚持从用户表单Excel VBA中调用Public Subroutine。 我一直在试图把子程序放到一个模块中,但是还是给了我一个错误(Sub或Function not defined!)

你能请指导在正确的方向。

模块1中的函数本身

Public Sub Check(j As Integer) If Worksheets("VBA").Cells(j, 19).Value = "Y" Then imgA.Visible = True imgB.Visible = False imgC.Visible = False imgD.Visible = False ElseIf Worksheets("VBA").Cells(j, 19).Value = "N" Then imgA.Visible = False imgB.Visible = True imgC.Visible = False imgD.Visible = False ElseIf Worksheets("VBA").Cells(j, 19).Value = "X" Then imgA.Visible = False imgB.Visible = False imgC.Visible = True imgD.Visible = False ElseIf Worksheets("VBA").Cells(j, 19).Value = "F" Then imgA.Visible = False imgB.Visible = False imgC.Visible = False imgD.Visible = True End If End Sub 

在这里,我在一个用户表单中调用它

  Private Sub UserForm_Initialize() Call Check(i) End Sub 

不打算作为您当前问题的答案。 只是一个build议:

 Public Sub Check(j As Integer) Dim v v = Worksheets("VBA").Cells(j, 19).Value imgA.Visible = (v = "Y") imgB.Visible = (v = "N") imgC.Visible = (v = "X") imgD.Visible = (v = "F") End Sub