Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 字典编译错误:找不到方法或数据成员_Excel_Vba - Fatal编程技术网

Excel 字典编译错误:找不到方法或数据成员

Excel 字典编译错误:找不到方法或数据成员,excel,vba,Excel,Vba,不确定为什么会出现上述错误。我有一个名为clsRemit的类模块,其中包含以下代码: Sub clsRemit() Public vendor As String Public amount As Long Public invoices As String End Sub 在我的模块中,我有: For Each v In dictlist.Keys If InStr(1, .Cells(q, "B").Value2, v, vbTextCompare) Then

不确定为什么会出现上述错误。我有一个名为
clsRemit
的类模块,其中包含以下代码:

Sub clsRemit()

Public vendor As String
Public amount As Long
Public invoices As String

End Sub
在我的模块中,我有:

For Each v In dictlist.Keys
    If InStr(1, .Cells(q, "B").Value2, v, vbTextCompare) Then
        vendor = .Cells(q, "B").Value2

        If dict.Exists(vendor) = True Then
            Set oVend = dict(vendor)
        Else
            Set oVend = New clsRemit
            dict.Add vendor, oVend
        End If

        oVend.vendor = vendor 'error here
        oVend.invoices = oVend.invoices & vbCrLf & .Cells(q, "F")
        oVend.amount = oVend.amount + .Cells(q, "G").Value
    End If
Next
那是一条红鲱鱼。真正的问题在于:

Public
(或
Private
,就这一点而言)在程序范围内是非法的。删除过程范围后,代码应编译:

Option Explicit
Public vendor As String
Public amount As Long
Public invoices As String

如果
clsRemit
代码错误,
Public
无法在过程范围内编译。是否确实存在
Sub clsRemit
,或者该类有3个公共字段?clsRemit中的代码不应包装在Sub中。变量应暗显为private,然后通过公共属性访问@Tragamor公共字段在clsRemit默认接口中以public get+let属性的形式公开-如果该类只是一个DTO,那么显式属性很可能是overkill/redundant.Huh。我不知道类模块可以只是声明@findwindow正如我在另一篇评论中所说,类模块中的
Public vendor as String
完全等同于拥有
Public Property Get vendor()as String
Public Property Let vendor(ByVal RHS as String)
成员;添加另一个类并将
实现clsreit
放入其中-编译器将强制您为正在实现的类公开的每个公共字段实现get+let访问器。请阅读class@findwindow我是问题中的马特lol-你会喜欢该博客上最近的“我不是程序员”帖子;-)啊,好的。原来是你!好久不见findwindow我觉得你应该写一个编译器…Rubberduck的解析器每天都在接近这个目标!当VBE看到它的时候(如果不是更好的话),我会认为它是“完成”的。在那时,编写一个TrpSpLoad将是一个真正的可能性(例如,输入VBA代码,输出C语言互操作,甚至是打印代码)。
Sub clsRemit()

Public vendor As String
Public amount As Long
Public invoices As String

End Sub
Option Explicit
Public vendor As String
Public amount As Long
Public invoices As String