excel - 如何将用户定义类型传递给 VBA 函数?
问题描述
这似乎应该很容易实现,但我目前正在努力,任何帮助将不胜感激。
我有一个用户定义类型,它定义了 4 个与日期信息相关的字段。我想将链接到这种类型的变量传递给一个函数,每个月都进行索引。下面是类型,子和功能。
我知道该函数不知道 TestMDate 类型,我尝试在函数中声明类型,但似乎没有任何效果。
提前谢谢了
格鲁瓦
''''''''''''''''''''''''''''''''
'UDT
''''''''''''''''''''''''''''''''
Private Type TestMDate
MonthS As String
MonthD As String
StartD As String
EndD As String
End Type
''''''''''''''''''''''''''''''''
'Sub
''''''''''''''''''''''''''''''''
Sub UpdateChart()
Dim Tstruct(12) As TestMDate
Dim a As Integer, i As Integer
''''''''''''''''''''''''''''''''
'
''''''''''''''''''''''''''''''''
Tstruct(1).MonthS = "Jan"
Tstruct(1).MonthD = "01"
Tstruct(1).StartD = "01"
Tstruct(1).EndD = "31"
Tstruct(2).MonthS = "Feb"
Tstruct(2).MonthD = "02"
Tstruct(2).StartD = "01"
Tstruct(2).EndD = "28"
Tstruct(3).MonthS = "Mar"
Tstruct(3).MonthD = "03"
Tstruct(3).StartD = "01"
Tstruct(3).EndD = "31"
Tstruct(4).MonthS = "Apr"
Tstruct(4).MonthD = "04"
Tstruct(4).StartD = "01"
Tstruct(4).EndD = "30"
Tstruct(5).MonthS = "May"
Tstruct(5).MonthD = "05"
Tstruct(5).StartD = "01"
Tstruct(5).EndD = "31"
Tstruct(6).MonthS = "Jun"
Tstruct(6).MonthD = "06"
Tstruct(6).StartD = "01"
Tstruct(6).EndD = "30"
Tstruct(7).MonthS = "Jul"
Tstruct(7).MonthD = "07"
Tstruct(7).StartD = "01"
Tstruct(7).EndD = "31"
Tstruct(8).MonthS = "Aug"
Tstruct(8).MonthD = "08"
Tstruct(8).StartD = "01"
Tstruct(8).EndD = "31"
Tstruct(9).MonthS = "Sep"
Tstruct(9).MonthD = "09"
Tstruct(9).StartD = "01"
Tstruct(9).EndD = "30"
Tstruct(10).MonthS = "Oct"
Tstruct(10).MonthD = "10"
Tstruct(10).StartD = "01"
Tstruct(10).EndD = "31"
Tstruct(11).MonthS = "Nov"
Tstruct(11).MonthD = "11"
Tstruct(11).StartD = "01"
Tstruct(11).EndD = "30"
Tstruct(12).MonthS = "Dec"
Tstruct(12).MonthD = "12"
Tstruct(12).StartD = "01"
Tstruct(12).EndD = "31"
For i = 1 To 12
a = proc_res_field(Tstruct(i))
Next i
End Sub
''''''''''''''''''''''''''''''''
'Function
''''''''''''''''''''''''''''''''
Function proc_res_field(Tstruct As TestMDate)
Debug.Print Tstruct.MonthS
Debug.Print Tstruct.MonthD
Debug.Print Tstruct.StartD
Debug.Print Tstruct.EndD
a = 1
End Function
解决方案
proc_res_field
不知道任何事情i
或a
Function proc_res_field(Tstruct As TestMDate)
Debug.Print Tstruct.MonthS
Debug.Print Tstruct.MonthD
Debug.Print Tstruct.StartD
Debug.Print Tstruct.EndD
proc_res_field = 1 '?
End Function
推荐阅读
- winforms - Powershell / Winforms 多个表单的位置
- arrays - 如何使用 VBA 过滤然后打印数组?
- java - MPAndroidChart, LineChart 在 x 轴的同一位置设置多个值
- python - 使用 Python 的 Easyguy 选择带有 fileopenbox 的文件,如何限制用户只选择一种文件类型,例如“.csv”或“pkl”
- autodesk-forge - 如何直接从 Design Automation 下载结果?
- css - CSS Grid:用多种尺寸的列包装
- amazon-web-services - DynamoDB 如何能够同时实现 HA 和最终一致?
- excel - 使用日期公式更新excel中的下拉列表
- c++ - 不同命名空间中的 Gtesting 类型参数化测试实例化和注册
- angular - 从 Angular (TP) 向 Flask 发布请求未在控制台中显示