|

楼主 |
发表于 2017-3-9 17:31
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
建立子类——日
1、通过Private Sub Class_Initialize()进行类初始化,设定相关参数
2、通过Property Get Values() As Variant引用该子类的Values时,返回该子类所包含的数值的数组
3、通过Property Get Address() As String引用该子类的Address时,返回该子类所包含的数值的所在单元格地址的字符串
4、通过Property Get MaxDay() As Integer 引用该子类的MaxDay时,返回月份最后一天的日数
5、因为每月的选值区域随年月在变化,故通过Property Let vYear(ByVal nEnter As Integer) 来设置日期的年份,Property Let vMonth(ByVal nEnter As Integer) 来设置日期的月份
日子类代码
- Private rDay As Range
- Private vDay As Variant
- Private nYear As Integer, nMonth As Integer
- Private nMaxDay As Integer
- Private Sub Class_Initialize()
- nYear = Year(Date)
- nMonth = Month(Date)
- 初始化
- End Sub
- Property Get MaxDay() As Integer '返回月份最后一天的日数
- MaxDay = Day(DateSerial(nYear, nMonth + 1, 1) - 1)
- End Property
- Property Get Values() As Variant '返回日期的数组
- Values = vDay
- End Property
- Property Get Address() As String '返回日期的单元格地址的字符串
- Address = "基本资料!$A$2:$A$" & (nMaxDay + 1)
- End Property
- Property Let vYear(ByVal nEnter As Integer) '设置日期的年份
- nYear = nEnter
- 初始化
- End Property
- Property Let vMonth(ByVal nEnter As Integer) '设置日期的月份
- nMonth = nEnter
- 初始化
- End Property
- Sub Reset() '重置
- Class_Initialize
- End Sub
- Private Sub 初始化()
- nMaxDay = Day(DateSerial(nYear, nMonth + 1, 1) - 1)
- Set rDay = Sheets("基本资料").[A2].Resize(nMaxDay)
- vDay = rDay.Value
- End Sub
复制代码
|
|