none
Macro - Set Field Value - NonEnglish Language RRS feed

  • Question

  • Hi,

    I have written a vba macro to set few oob fields(ex: Task Name, Predecessors, etc...). Code is working fine with the English language version of MS Project Professional(2013) but same code was throwing error with different languages as "this is not a valid field name" (i translated :) ).

    Code ex below. In this, column Predecessors doesn't exist in non-english languages.

    SetTaskField Field:="Predecessors", Value:="1"

    So is there any way referring field by internal or any unique name that doesn't change with the language?   


    Thanks, Ram

    Monday, February 8, 2016 6:50 PM

Answers

  • Kodana,

    As long as your code is referring to a field by it's string name, you will have to modify it for each language. However, if you refer to the field by the fieldID or refer to it via the object reference, the code should run without problems regardless of language.

    For example, in your case try the SetTaskFieldbyID Method instead of the SetTaskField Method.

    Or, for a direct object reference, the following will work:

    ActiveProject.Tasks(1).Predecessors = "1"

    Hope this helps.

    John

    Monday, February 8, 2016 7:26 PM

All replies

  • Kodana,

    As long as your code is referring to a field by it's string name, you will have to modify it for each language. However, if you refer to the field by the fieldID or refer to it via the object reference, the code should run without problems regardless of language.

    For example, in your case try the SetTaskFieldbyID Method instead of the SetTaskField Method.

    Or, for a direct object reference, the following will work:

    ActiveProject.Tasks(1).Predecessors = "1"

    Hope this helps.

    John

    Monday, February 8, 2016 7:26 PM
  • Hi,

    not sure what you exactly want to do. At the moment, you seem to "edit" fields as displayed in current view. This approach is always language related. Try to use object model, e.g.

    Sub Pred()
    Dim T As Task
    
    For Each T In ActiveProject.Tasks
        If Not T Is Nothing Then
            If <whatever you need> Then
                T.Predecessors = 1
            End If
        End If
    Next T
    End Sub

    Feel free to give a description what you want to do, I assume we will be able to help.

    Regards
    Barbara


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!

    Monday, February 8, 2016 7:29 PM
    Moderator
  • Thank you John. I'll try and update here.

    Thanks, Ram

    Monday, February 8, 2016 8:16 PM
  • Thanks for your reply Barbara.

    I'm trying to update built-in or default available fields(for instance "Predecessors") through macro code. 

    As John suggested, i'll try and share the outcome. Thank you both again for trying to help me.


    Thanks, Ram

    Monday, February 8, 2016 8:19 PM
  • Ram,

    You're welcome and thanks for the feedback.

    John

    Tuesday, February 9, 2016 1:59 AM