gpt4 book ai didi

excel - VBA 自定义集合错误 - (对象变量或未设置 block 变量)

转载 作者:行者123 更新时间:2023-12-04 21:51:27 26 4
gpt4 key购买 nike

我已经在 VBA 上设置了一个自定义集合,以便存储工作表中的多个对象并遍历这些项目以创建一个 ppt 演示文稿。

不幸的是,我在创建自定义集合时遇到了障碍:我将其设置如下并获得 对象变量或带有 block 变量错误

Sub Funds()
Dim Funds As Collection
Dim V As Fund
Set V = New Fund

V.FundID = "V1"
V.Title = "Profile_FactSheet_Title_En"
V.Fund_MER = "V1_Mer_En"
V.Fund_Yield = "V1_Yield_End"
V.Asset_Alloc = "V1_assetAlloc_En_SourceData"
V.Asset_Alloc2 = "AAV1EN"
V.Asset_Alloc3 = "FIV1EN"
V.Asset_Alloc4 = "FIMAV1EN"
V.Title_2 = "Profile_FactSheet_Title_En"
V.Trailing = "RetV1TrailingEN"
V.Calendar = "RetV1CalendarEN"

Funds.Add V, V.FundID

结束子

当我查看此内容时,我认为一切都已正确设置,但我仍然收到该错误。

此外,我有一个用于集合中对象的类模块,如下所示:
Option Explicit

Public FundID As String
Public Title As String
Public Fund_MER As String
Public Fund_Yield As String
Public Asset_Alloc As String
Public Asset_Alloc2 As String
Public Asset_Alloc3 As String
Public Asset_Alloc4 As String
Public Title_2 As String
Public Trailing As String
Public Calendar As String

对此的任何帮助将不胜感激!

最佳答案

不要给您的收藏和子取相同的名称(基金)。你要么需要做:

Dim Funds As Collection
Set Funds = New Collection

或者
Dim Funds As New Collection

关于excel - VBA 自定义集合错误 - (对象变量或未设置 block 变量),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53284540/

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