0
votes

I try to change the title of the task fields Text1 to Text30 in Microsoft Project 2007 using VBA.

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”.

But I 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.

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/bb221254(office.12).aspx

I’d be glad to get this fixed!

Thanks in advance for helping out!

Cheers

B

1

1 Answers

2
votes

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

Help on CustomFieldRename

Help on CustomFieldGetName