循环浏览MS Project的每个字段 [英] Loop through each field for MS Project

查看:124
本文介绍了循环浏览MS Project的每个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图遍历我的MS Project文件中的每个字段,并收集有关该字段的信息(特定的自定义名称).最简单的方法是什么?

I am trying to loop through each field in my MS Project file and gather information about that field (custom name is particular). What is the easiest way to do this?

谢谢

推荐答案

要获取字段的自定义名称,您需要字段常量并遍历所有字段,您需要存储所有字段常量的列表.

To get the custom name of a field you'll need the field constant and to loop through all fields, you'll need to store a list of all field constants.

这是一个入门的简单示例.我对Task Text1-30字段的字段常量数组进行了硬编码.

Here is a simple example to get you started. I hard-coded an array of the field constants for the Task Text1-30 fields.

Sub GetCustomFieldNames()

    Dim TextFields As Variant
    TextFields = Array(188743731, 188743734, 188743737, 188743740, 188743743 _
        , 188743746, 188743747, 188743748, 188743749, 188743750, 188743997, 188743998 _
        , 188743999, 188744000, 188744001, 188744002, 188744003, 188744004, 188744005 _
        , 188744006, 188744007, 188744008, 188744009, 188744010, 188744011, 188744012 _
        , 188744013, 188744014, 188744015, 188744016)

    Dim FldID As Variant

    For Each FldID In TextFields
        If Len(CustomFieldGetName(FldID)) > 0 Then
            Debug.Print FieldConstantToFieldName(FldID), CustomFieldGetName(FldID)
        End If
    Next FldID

End Sub

以下是对此进行改进的几种方法:

Here are a few ways to improve on this:

  • 用枚举常量替换数字值(例如pjTaskText1)
  • 将字段列表存储在外部文件(例如包含字段名称,字段常量等的csv文件)中
  • 如果宏存储在仅宏项目文件中,则可以将字段存储在资源表中,并通过遍历资源来遍历字段(请参见屏幕快照).

这篇关于循环浏览MS Project的每个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆