Using VBA to return a field value of a given task ID in MS Project












0















This is probably really simple (I am new to VBA in MS Project - Excel is more my specialty) but I am just looking to return a value of selected field in MS Project based on a given Task ID. I (unsuccessfully) tried this:



ActiveProject.Tasks.UniqueID(1).GetField(Number2)


...but hopefully that shows what I am trying to achieve which is finding the value of the Number2 field in the first Task of a project.










share|improve this question





























    0















    This is probably really simple (I am new to VBA in MS Project - Excel is more my specialty) but I am just looking to return a value of selected field in MS Project based on a given Task ID. I (unsuccessfully) tried this:



    ActiveProject.Tasks.UniqueID(1).GetField(Number2)


    ...but hopefully that shows what I am trying to achieve which is finding the value of the Number2 field in the first Task of a project.










    share|improve this question



























      0












      0








      0








      This is probably really simple (I am new to VBA in MS Project - Excel is more my specialty) but I am just looking to return a value of selected field in MS Project based on a given Task ID. I (unsuccessfully) tried this:



      ActiveProject.Tasks.UniqueID(1).GetField(Number2)


      ...but hopefully that shows what I am trying to achieve which is finding the value of the Number2 field in the first Task of a project.










      share|improve this question
















      This is probably really simple (I am new to VBA in MS Project - Excel is more my specialty) but I am just looking to return a value of selected field in MS Project based on a given Task ID. I (unsuccessfully) tried this:



      ActiveProject.Tasks.UniqueID(1).GetField(Number2)


      ...but hopefully that shows what I am trying to achieve which is finding the value of the Number2 field in the first Task of a project.







      vba ms-project






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 '18 at 2:13









      BigBen

      6,4872619




      6,4872619










      asked Nov 28 '18 at 2:09









      Marko ManenicaMarko Manenica

      354




      354
























          2 Answers
          2






          active

          oldest

          votes


















          1














          To get the value of the Number2 field of a particular Task by ID:



          ActiveProject.Tasks(3).Number2


          To get the value by Task Unique ID:



          ActiveProject.Tasks.UniqueID(3).Number2


          To get the value of the Number2 field of the first selected task:



          ActiveSelection.Tasks(1).Number2


          The GetField method is useful if a variable field name is to be used:



          ActiveProject.Tasks(3).GetField (pjTaskNumber2)





          share|improve this answer
























          • Note that Task ID and Task Unique ID are often different. Task ID represents the order of the tasks in the schedule whereas the Unique ID is assigned sequentially when tasks are added, regardless of position within the schedule.

            – Rachel Hettinger
            Nov 28 '18 at 5:04











          • Great thanks! The ActiveSelection.Tasks... also solved another issue I was having

            – Marko Manenica
            Nov 28 '18 at 6:24





















          0














          You should try ActiveProject.Tasks(1)... to get the first task of the tasks collection:



          (https://docs.microsoft.com/en-us/office/vba/api/project.tasks(object))






          share|improve this answer
























          • I tried that but because the current active task is below the first task the Tasks(1) is starting from that current active task. I read that you need UniqueID to return a specific ID (that is not baselined from the current active task). Or am I missing something?

            – Marko Manenica
            Nov 28 '18 at 2:37













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53511064%2fusing-vba-to-return-a-field-value-of-a-given-task-id-in-ms-project%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          To get the value of the Number2 field of a particular Task by ID:



          ActiveProject.Tasks(3).Number2


          To get the value by Task Unique ID:



          ActiveProject.Tasks.UniqueID(3).Number2


          To get the value of the Number2 field of the first selected task:



          ActiveSelection.Tasks(1).Number2


          The GetField method is useful if a variable field name is to be used:



          ActiveProject.Tasks(3).GetField (pjTaskNumber2)





          share|improve this answer
























          • Note that Task ID and Task Unique ID are often different. Task ID represents the order of the tasks in the schedule whereas the Unique ID is assigned sequentially when tasks are added, regardless of position within the schedule.

            – Rachel Hettinger
            Nov 28 '18 at 5:04











          • Great thanks! The ActiveSelection.Tasks... also solved another issue I was having

            – Marko Manenica
            Nov 28 '18 at 6:24


















          1














          To get the value of the Number2 field of a particular Task by ID:



          ActiveProject.Tasks(3).Number2


          To get the value by Task Unique ID:



          ActiveProject.Tasks.UniqueID(3).Number2


          To get the value of the Number2 field of the first selected task:



          ActiveSelection.Tasks(1).Number2


          The GetField method is useful if a variable field name is to be used:



          ActiveProject.Tasks(3).GetField (pjTaskNumber2)





          share|improve this answer
























          • Note that Task ID and Task Unique ID are often different. Task ID represents the order of the tasks in the schedule whereas the Unique ID is assigned sequentially when tasks are added, regardless of position within the schedule.

            – Rachel Hettinger
            Nov 28 '18 at 5:04











          • Great thanks! The ActiveSelection.Tasks... also solved another issue I was having

            – Marko Manenica
            Nov 28 '18 at 6:24
















          1












          1








          1







          To get the value of the Number2 field of a particular Task by ID:



          ActiveProject.Tasks(3).Number2


          To get the value by Task Unique ID:



          ActiveProject.Tasks.UniqueID(3).Number2


          To get the value of the Number2 field of the first selected task:



          ActiveSelection.Tasks(1).Number2


          The GetField method is useful if a variable field name is to be used:



          ActiveProject.Tasks(3).GetField (pjTaskNumber2)





          share|improve this answer













          To get the value of the Number2 field of a particular Task by ID:



          ActiveProject.Tasks(3).Number2


          To get the value by Task Unique ID:



          ActiveProject.Tasks.UniqueID(3).Number2


          To get the value of the Number2 field of the first selected task:



          ActiveSelection.Tasks(1).Number2


          The GetField method is useful if a variable field name is to be used:



          ActiveProject.Tasks(3).GetField (pjTaskNumber2)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 28 '18 at 5:02









          Rachel HettingerRachel Hettinger

          5,88321726




          5,88321726













          • Note that Task ID and Task Unique ID are often different. Task ID represents the order of the tasks in the schedule whereas the Unique ID is assigned sequentially when tasks are added, regardless of position within the schedule.

            – Rachel Hettinger
            Nov 28 '18 at 5:04











          • Great thanks! The ActiveSelection.Tasks... also solved another issue I was having

            – Marko Manenica
            Nov 28 '18 at 6:24





















          • Note that Task ID and Task Unique ID are often different. Task ID represents the order of the tasks in the schedule whereas the Unique ID is assigned sequentially when tasks are added, regardless of position within the schedule.

            – Rachel Hettinger
            Nov 28 '18 at 5:04











          • Great thanks! The ActiveSelection.Tasks... also solved another issue I was having

            – Marko Manenica
            Nov 28 '18 at 6:24



















          Note that Task ID and Task Unique ID are often different. Task ID represents the order of the tasks in the schedule whereas the Unique ID is assigned sequentially when tasks are added, regardless of position within the schedule.

          – Rachel Hettinger
          Nov 28 '18 at 5:04





          Note that Task ID and Task Unique ID are often different. Task ID represents the order of the tasks in the schedule whereas the Unique ID is assigned sequentially when tasks are added, regardless of position within the schedule.

          – Rachel Hettinger
          Nov 28 '18 at 5:04













          Great thanks! The ActiveSelection.Tasks... also solved another issue I was having

          – Marko Manenica
          Nov 28 '18 at 6:24







          Great thanks! The ActiveSelection.Tasks... also solved another issue I was having

          – Marko Manenica
          Nov 28 '18 at 6:24















          0














          You should try ActiveProject.Tasks(1)... to get the first task of the tasks collection:



          (https://docs.microsoft.com/en-us/office/vba/api/project.tasks(object))






          share|improve this answer
























          • I tried that but because the current active task is below the first task the Tasks(1) is starting from that current active task. I read that you need UniqueID to return a specific ID (that is not baselined from the current active task). Or am I missing something?

            – Marko Manenica
            Nov 28 '18 at 2:37


















          0














          You should try ActiveProject.Tasks(1)... to get the first task of the tasks collection:



          (https://docs.microsoft.com/en-us/office/vba/api/project.tasks(object))






          share|improve this answer
























          • I tried that but because the current active task is below the first task the Tasks(1) is starting from that current active task. I read that you need UniqueID to return a specific ID (that is not baselined from the current active task). Or am I missing something?

            – Marko Manenica
            Nov 28 '18 at 2:37
















          0












          0








          0







          You should try ActiveProject.Tasks(1)... to get the first task of the tasks collection:



          (https://docs.microsoft.com/en-us/office/vba/api/project.tasks(object))






          share|improve this answer













          You should try ActiveProject.Tasks(1)... to get the first task of the tasks collection:



          (https://docs.microsoft.com/en-us/office/vba/api/project.tasks(object))







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 28 '18 at 2:28









          Emilio Lucas CeroleniEmilio Lucas Ceroleni

          1,2252610




          1,2252610













          • I tried that but because the current active task is below the first task the Tasks(1) is starting from that current active task. I read that you need UniqueID to return a specific ID (that is not baselined from the current active task). Or am I missing something?

            – Marko Manenica
            Nov 28 '18 at 2:37





















          • I tried that but because the current active task is below the first task the Tasks(1) is starting from that current active task. I read that you need UniqueID to return a specific ID (that is not baselined from the current active task). Or am I missing something?

            – Marko Manenica
            Nov 28 '18 at 2:37



















          I tried that but because the current active task is below the first task the Tasks(1) is starting from that current active task. I read that you need UniqueID to return a specific ID (that is not baselined from the current active task). Or am I missing something?

          – Marko Manenica
          Nov 28 '18 at 2:37







          I tried that but because the current active task is below the first task the Tasks(1) is starting from that current active task. I read that you need UniqueID to return a specific ID (that is not baselined from the current active task). Or am I missing something?

          – Marko Manenica
          Nov 28 '18 at 2:37




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53511064%2fusing-vba-to-return-a-field-value-of-a-given-task-id-in-ms-project%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)