gpt4 book ai didi

excel - VBA 函数 - 参数不可选

转载 作者:行者123 更新时间:2023-12-01 18:41:30 31 4
gpt4 key购买 nike

Public Function RETURN_Equipment(Optional category As String) As Collection
Dim config As classConfiguration
Set config = New classConfiguration

Dim item As classItem
Set item = New classItem

Dim myCollection As Collection
Set myCollection = New Collection

For Each config In Configurations
For Each item In config.colItems
If IsMissing(category) Then
myCollection.add item
ElseIf InStr(category, "mainframe") <> 0 And item.category = "mainframe" Then
myCollection.add item
MsgBox "Fired!"
ElseIf category = "accessory" And item.category = "accessory" Then
Else
End If
Next
Next

RETURN_Equipment = myCollection
End Function

我不断得到

Compile error:
Argument not optional

我在最后一行收到错误

RETURN_Equipment = myCollection

我理解错误消息,它告诉我我没有填写参数。但我只有一个参数,并且我已将其声明为可选。看起来代码认为我正在尝试从函数调用该函数?

什么给出了?

最佳答案

任何时候分配一个对象时,都需要使用set关键字。

设置 RETURN_Equipment = myCollection

关于excel - VBA 函数 - 参数不可选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23574083/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com