Using VBA to return a field value of a given task ID in MS Project
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
add a comment |
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
add a comment |
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
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
vba ms-project
edited Nov 28 '18 at 2:13
BigBen
6,4872619
6,4872619
asked Nov 28 '18 at 2:09
Marko ManenicaMarko Manenica
354
354
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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)
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
add a comment |
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))
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
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
add a comment |
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)
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
add a comment |
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)
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)
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
add a comment |
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
add a comment |
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))
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
add a comment |
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))
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
add a comment |
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))
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))
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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