MSProject中的VBA中的错误如何检查主项目中是否加载了子项目?

时间:2016-06-10 12:15:24

标签: vba macros ms-project

如果我对tmp变量进行监视并且在If Not tmp Then行停止,则两者都显示为true,即I.e. tmp为True,Not tmp为True。

Dim subProj As Subproject
For Each subProj In prj.Subprojects
    Dim tmp As Boolean
    tmp = subProj.IsLoaded
    If Not tmp Then
        ExportTaskToExcel subProj.SourceProject, StartDate, EndDate
    End If
Next

如何检查主项目中是否未加载(未扩展)子项目?

Look at image under this link which is showing that in the same time: True = not True

1 个答案:

答案 0 :(得分:0)

有可能你在其他地方声明了tmp,这可以从这里看到导致这个问题(即它在另一个模块中声明为public)。尝试更改名称以隔离它,同样,我以前从未在循环中声明变量,虽然我不确定其含义,但我不推荐它。

Dim subProj As Subproject
Dim tmp10 As Boolean
For Each subProj In prj.Subprojects
    tmp10 = subProj.IsLoaded
    If Not tmp10 Then
        ExportTaskToExcel subProj.SourceProject, StartDate, EndDate
    End If
Next

您可能出于特定原因而已完成此操作,但您可以完全省略该变量: -

Dim subProj As Subproject
For Each subProj In prj.Subprojects
    If Not subProj.IsLoaded Then
        ExportTaskToExcel subProj.SourceProject, StartDate, EndDate
    End If
Next