我的工作簿中有一个名为Control的工作表,在我的vba函数中,它没有被识别。为什么呢?
Private Sub Class_Initialize()
On Error GoTo handler
Set m_connectionSettingsSheet = GetWorkSheet("Control")
Userid = ValueOfNameInSheetStartingWith("userName", "Control")
Pwd = PasswordForm.TextBox1.value
'Pwd = ValueOfNameInSheetStartingWith("password", "Control")
'ServerBaseAddress = m_connectionSettingsSheet.Range("ServerBaseAddress").value
ServerBaseAddress = ValueOfNameInSheetStartingWith("ServerBaseAddress", "Control")
在类ImporterSetup中,我从工作表的单元格中获取字段用户名,密码和URL#34; Control"。这是来自Jira的Excel导入
验证工作表是否存在的函数是:
Private Function GetWorkSheet(workSheetName As String) As Worksheet
If WorksheetExists(workSheetName) Then
GetWorkSheet = WorksheetExists(workSheetName)
Else
MsgBox ("Must have the worksheet named " & workSheetName)
End If
End Function
Private Function WorksheetExists(ByVal workSheetName As String) As Boolean
IsExists = False
For Each ws In Worksheets
If workSheetName = ws.name Then
IsExists = True
Exit Function
End If
Next ws
End Function
答案 0 :(得分:1)
有两种方法可以解决这个问题,但它们都涉及\r\n\1
功能。在此函数中,您不会设置WorksheetExists
的值,因此它将始终返回默认值WorksheetExists
。
第一种解决方法是:
False
其次是:
Private Function WorksheetExists(ByVal workSheetName As String) As Boolean
For Each ws In Worksheets
If workSheetName = ws.name Then
WorksheetExists = True
Exit Function
End If
Next ws
End Function
答案 1 :(得分:1)
工作表存在功能需要像下面这样更新:
Private Function WorksheetExists(ByVal workSheetName As String) As Boolean
WorksheetExists = False
For Each ws In Worksheets
If workSheetName = ws.name Then
WorksheetExists= True
Exit Function
End If
Next ws
End Function