0

我尝试使用 VBA 在 Microsoft Project 2007 中将任务字段 Text1 的标题更改为 Text30。

这是我手动执行的操作:

在甘特图任务表中,单击表头并添加一列。在弹出窗口中,我可以选择要添加的任务属性,在我的例子中是“Text1”,我可以输入标题,例如“my text1”。

我不在乎这张桌子。我想将标题赋予文本字段。我想将 Text1 到 Text30 导出到 XML 文件,并且也想导出字段的标题,所以我需要获取标题并且我喜欢设置它,因为即使它没有在表格中使用它也应该是出口。

这是我写的只是为了测试:

Private Sub setfieldtitletryout()
  Dim i As Integer
  Dim c As Long
  For i = 1 To 30
    c = FieldNameToFieldConstant("Text" & i, pjTask)
    Debug.Print "Text" & i; " has constant " & c
    Debug.Print "  Name of Text" & i; " is " & FieldConstantToFieldName(c) ' well what a surprise...
    SetFieldTitle(c, ListOfNames(i)) ' Oviously doesn't work, because the function doesn't exist :-(
    Debug.Print "  Title of Text" & i; " is " & FieldConstantToFieldTitle(c) ' unfortunately doen't exist too
  Next
End Sub

这是我检查但没有准备好帮助我的内容......</p>

http://msdn.microsoft.com/en-us/library/bb221504(office.12).aspx

http://msdn.microsoft.com/en-us/library/bb221254(office.12).aspx

我很高兴能解决这个问题!

提前感谢您的帮助!

干杯

4

1 回答 1

2

好吧,我做到了:-)

Private Sub setfieldtitletryout()
  Dim i As Integer
  Dim c As Long
  For i = 1 To 5
    c = FieldNameToFieldConstant("Text" & i, pjTask) ' get constant of custom field by name
    Debug.Print i & ". Rename title of Text" & i
    Debug.Print "   Name of Text" & i; " is '" & FieldConstantToFieldName(c) & "'"

    CustomFieldRename FieldID:=c, NewName:="Titel of Text " & i  'Rename/set custom field title
    Debug.Print "   Title of Text" & i; " is '" & CustomFieldGetName(c) & "'" ' get title of custom field
  Next
End Sub

http://msdn.microsoft.com/en-us/library/ms453877(v=office.12).aspx

CustomFieldRename帮助

关于CustomFieldGetName的帮助

于 2011-04-05T19:47:00.960 回答