MS Project VBA 获取或设置自定义任务字段的标题 Text1..Text30
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5550266/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MS Project VBA getting or setting Title of custom task field Text1..Text30
提问by BBQ Chef
I try to change the title of the task fields Text1 to Text30 in Microsoft Project 2007 using VBA.
我尝试使用 VBA 在 Microsoft Project 2007 中将任务字段 Text1 的标题更改为 Text30。
Here is what I do manually:
这是我手动执行的操作:
In Gant Chart Task Table click on table header and add a column. In the popup I can select which task property to add, in my case “Text1” and I can enter a title, for example “my text1”.
在甘特图任务表中,单击表标题并添加一列。在弹出窗口中,我可以选择要添加的任务属性,在我的例子中是“Text1”,我可以输入一个标题,例如“my text1”。
ButI don't care about the table. I want to give the title to the text field. I want to export Text1 to Text30 to an XML file and like to export the title of the field as well, so I need to get the title and I like to set it, because even if it isn't used in a table it shallbe exported.
但我不在乎桌子。我想为文本字段提供标题。我想将 Text1 到 Text30 导出到一个 XML 文件中,并且也想导出字段的标题,所以我需要获取标题并且我喜欢设置它,因为即使它不在表中使用它也应该出口。
Here is what I wrote just for testing:
这是我写的只是为了测试:
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
Here is what I checked but did not ready help me…
这是我检查过但没有准备好的帮助我......
http://msdn.microsoft.com/en-us/library/bb221504(office.12).aspx
http://msdn.microsoft.com/en-us/library/bb221504(office.12).aspx
http://msdn.microsoft.com/en-us/library/bb221254(office.12).aspx
http://msdn.microsoft.com/en-us/library/bb221254(office.12).aspx
I'd be glad to get this fixed!
我很乐意解决这个问题!
Thanks in advance for helping out!
提前感谢您的帮助!
Cheers
干杯
B
乙
回答by BBQ Chef
Well I did it :-)
好吧,我做到了:-)
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
http://msdn.microsoft.com/en-us/library/ms453877(v=office.12).aspx
Help on CustomFieldRename
Help on CustomFieldGetName