VBA功能-参数不是可选的 [英] VBA Function - Argument Not Optional

查看:458
本文介绍了VBA功能-参数不是可选的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

I understand the error message, its telling me I did not fill out a parameter. But I only have one parameter, and I've declared it optional. It looks like the code thinks I'm trying to call the function from the function?

有什么作用?

推荐答案

每次分配对象时,都需要使用set关键字.

Anytime you assign an object you need to use the set keyword.

set RETURN_Equipment = myCollection

这篇关于VBA功能-参数不是可选的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆