从 1984年 2149年指定年份的 月数 集合中获取项的数目。 只读 Integer。
语法
表达式。计数
表达 一个代表“Months”对象的变量。
示例
下面的示例在 即时窗口中的 VBE 返回 12,2012年中的月数。 如果设置为 1983年或 2150 年,结果是"运行时错误"1101";该参数是无效。
? activeproject.Resources(1).Calendar.Years(2012).Months.Count
下面的示例演示如何使用 Count属性为 Assignments对象。 它会提示用户输入资源的名称,然后将该资源分配给没有任何资源的任务。
Sub AssignResource()
Dim T As Task ' Task object used in For Each loop
Dim R As Resource ' Resource object used in For Each loop
Dim Rname As String ' Resource name
Dim RID As Long ' Resource ID
RID = 0
RName = InputBox$("Enter the name of a resource: ")
For Each R in ActiveProject.Resources
If R.Name = RName Then
RID = R.ID
Exit For
End If
Next R
If RID <> 0 Then
' Assign the resource to tasks without any resources.
For Each T In ActiveProject.Tasks
If T.Assignments.Count = 0 Then
T.Assignments.Add ResourceID:=RID
End If
Next T
Else
MsgBox Prompt:=RName & " is not a resource in this project.", buttons:=vbExclamation
End If
End Sub
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。