1
我收到錯誤450「參數數量錯誤或屬性賦值無效」。錯誤發生在函數的最後一行,即最後一行「End Function」。我看不出有任何缺失「結束如果」所以我不知道是什麼導致了這一點:「End Function」行Excel VBA 450錯誤
myDict = bpCreateDictionary("A", "B", 1, 10, "Sheet2", , "Ignore")
它引用這個功能:
Function bpCreateDictionary(ByVal KeyColumn As String, ByVal ValueColumn As String, _
Optional ByVal RowBegin As Long, Optional RowEnd As Long, _
Optional ByVal DataWorksheet As String = "Sheet1", _
Optional ByVal DataWorkbook As String, _
Optional ByVal HandleDuplicates As String, _
Optional ByVal KeepOpen As Boolean = False) As Dictionary
Application.ScreenUpdating = False
sCurrentActiveBook = ActiveWorkbook.Name
sCurrentActiveSheet = ActiveSheet.Name
Dim oDictionary As New Scripting.Dictionary
Dim lLastRow As Long
Dim lIncrementer As Long
Dim vKey As Variant
Dim vValue As Variant
If Not DataWorkbook = "" Then
oWorkbookName = bpGetFilenameFromPath(DataWorkbook)
Workbooks.Open (DataWorkbook)
Workbooks(oWorkbookName).Activate
sCurrentActiveExternalSheet = ActiveSheet.Name
End If
If Not DataWorksheet = "" Then
Worksheets(DataWorksheet).Activate
End If
If Not RowEnd = 0 Then
lLastRow = RowEnd
Else
lLastRow = bpLastRow(KeyColumn)
End If
If RowBegin = 0 Then
RowBegin = 1
End If
For lIncrementer = RowBegin To lLastRow
vKey = Cells(lIncrementer, KeyColumn)
vValue = Cells(lIncrementer, ValueColumn)
If HandleDuplicates = "Ignore" And oDictionary.Exists(vKey) Then
'Do Nothing and move to next row
Else
oDictionary.Add vKey, vValue
End If
Next lIncrementer
Set bpCreateDictionary = oDictionary
If Not oWorkbookName = "" Then
If Not KeepOpen = True Then
Worksheets(sCurrentActiveExternalSheet).Activate
Workbooks(oWorkbookName).Close SaveChanges:=False
End If
End If
Workbooks(sCurrentActiveBook).Activate
Worksheets(sCurrentActiveSheet).Activate
Application.ScreenUpdating = True
End Function
而且在最後一行「端功能」是哪裏調試時發生錯誤。任何想法可能會發生在這裏?
'設置myDict = bpCreateDictionary(...)'函數做? – GSerg
這就是GSerg,謝謝! – user4333011