![ms project vba assignments Microsoft Office Forums](https://www.office-forums.com/styles/default/custom/logo.png)
- Search forums
- Newsgroup Archive
- Project Newsgroups
- Project Developer
![](http://writinghelp.site/777/templates/cheerup2/res/banner1.gif)
adding tasks, resources and assignments to a project using VBA
- Thread starter Mark VII
- Start date May 3, 2007
- May 3, 2007
Greetings -- I'm working up a program to take a Excel list of tasks and resources and bring it into Project. (We have a standard estimating Excel template that is currently entered into Project manually, and am trying to automate this.) Am having trouble assigning resources to tasks. Here's a high level of how the code looks. dim tsk as Task dim rst as Resource dim asn as Assignment dim proj as Project set proj as Application.Projects.Add For each row on the input spreadsheet set tsk = proj.tasks.add tsk.Name = < task name from spreadsheet > '* this goes OK proj.Resources.Add (< resource name from spreadsheet > ) '* this goes OK lngResourceId = RetreiveResouceId(name) '* function to find resource and get its id '* trouble starts here Set asn = tsk.Assignments.Add(tsk.ID, lngResourceId, <units from spreadsheet>) asn.Work = < hours from spreadsheet > next input row Creating the task records goes OK. So does adding the resource and retrieving the resulting ID. Where it gets messy is creating the resource assignments. The "Set asn = tsk.Assingment...." gives 1101, The Argument Value is not Valid if I retrieve the units value from the spreadsheet (even if it's 1). However, the statement works OK if I hard code the units value to 1. If I run with units hard coded to 1, and reach the "asn.Work = < value from spreadsheet >" line, I get the 1101 error again. Have searched high and low for an example of the correct way to specify these values and come up dry. Does anyone have any suggestions? Thanks a million. Mark
Mark VII said: Greetings -- I'm working up a program to take a Excel list of tasks and resources and bring it into Project. (We have a standard estimating Excel template that is currently entered into Project manually, and am trying to automate this.) Am having trouble assigning resources to tasks. Here's a high level of how the code looks. dim tsk as Task dim rst as Resource dim asn as Assignment dim proj as Project set proj as Application.Projects.Add For each row on the input spreadsheet set tsk = proj.tasks.add tsk.Name = < task name from spreadsheet > '* this goes OK proj.Resources.Add (< resource name from spreadsheet > ) '* this goes OK lngResourceId = RetreiveResouceId(name) '* function to find resource and get its id '* trouble starts here Set asn = tsk.Assignments.Add(tsk.ID, lngResourceId, <units from spreadsheet>) asn.Work = < hours from spreadsheet > next input row Creating the task records goes OK. So does adding the resource and retrieving the resulting ID. Where it gets messy is creating the resource assignments. The "Set asn = tsk.Assingment...." gives 1101, The Argument Value is not Valid if I retrieve the units value from the spreadsheet (even if it's 1). However, the statement works OK if I hard code the units value to 1. If I run with units hard coded to 1, and reach the "asn.Work = < value from spreadsheet >" line, I get the 1101 error again. Have searched high and low for an example of the correct way to specify these values and come up dry. Does anyone have any suggestions? Thanks a million. Mark Click to expand...
John said: My first guess is that the units value in Excel is of the wrong data type, like maybe a text value. < Click to expand...
- May 4, 2007
Mark VII said: Hi John -- Good point. If I assign the contents of the relevant spreadsheet cell to a variable, then assign the variable to the Work property, it works. Go figure. Have run into a new problem, though. As I loop through the resources and populate their work values, numbers start changing strangely. For example, I assign resource1 to the task and let Units default to 100%. Then, I set his Work property to specify his hours. So far so good. (At this point, the task Work = resource1's work.) Then, I assign resource2 to the task, let his units default to 100%. Still OK. When I set resource2's work hours, I would expect project to set resource2's hours to the specified value, leave resource1's hours alone, and set the task work hours to the sum of resource1 and resource2's hours. Instead, project reduces resource1's work hours. Also, the task total work hours is a value lower than expected. Any thoughts here? Thanks, Mark Click to expand...
John said: The "numbers" are probably changing because of the default task type. < Click to expand...
- May 5, 2007
Mark VII said: I think that was it. I changed my code, and though not exactly as expected, the hours allocations for multiple resources per task are now much closer. Thanks a million for helping me get this program on line. It's going to save us a TON of time. Mark Click to expand...
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.
Similar Threads
0 | ||
0 | ||
1 | ||
0 | ||
0 | ||
0 | ||
0 | ||
0 |
Project Management, Software, Training...
« Securing Your MS Project Files and Macro Code | Main | Just needs a little dog to ride on the tank »
Working with Task and Assignment Fields VBA
One common problem people face with project is that there are three classes of custom fields; task fields, assignment fields and resource fields. If you are in a resource view and you are looking at the Text1 field it won't have the same information as if you are looking at the Text1 field in a task view. This is true with reports as well. The solution is to copy over the items from the one field to the other. This is painful unless you automate it. So, to reduce the pain here is VBA code which does it for you: Sub CopyTaskFieldToAssignment() 'This macro copies information in the task text5 field 'into the assignment text5 field so that is can 'be displayed in a usage view or in a report. 'Modify the line noted below to fit your needs Dim t As Task Dim ts As Tasks Dim a As Assignment Set ts = ActiveProject.Tasks For Each t In ts If Not t Is Nothing Then For Each a In t.Assignments 'change the following line to use 'for a different custom field a.Text5 = t.Text5 Next a End If Next t End Sub
Pretty easy. This one should have no problems because each assignment only has a single task that it references. However, going the other way could be a problem as each task can have several assignments. To sidestep the issue we can simply concatenate all of the text from all of the assignments. The code would then look like this:
Sub CopyAssignmentFieldToTask() Dim t As Task Dim ts As Tasks Dim a As Assignment Set ts = ActiveProject.Tasks For Each t In ts If Not t Is Nothing Then t.Text5 = "" For Each a In t.Assignments 'change the following line to use 'for a different custom field t.Text5 = t.Text5 & ", " & a.Text5 Next a End If Next t End Sub
The line t.Text5 = t.Text5 & ", " & a.Text5 appends whatever is in the assignment field to whatever is already existing in the task field.
Some simple modifications can make it work to copy from the resource fields.
Posted on August 2, 2005 4:39 PM | Permalink
Comments (3)
Disculpe que le escriba en español, mi consulta es: como puedo poner el valor de una variable creada en visual basic (ejemplo: avance) en la barra de gantt, hasta ahora solo puedo hacerlo con los campos que tiene ms project, pero no encuentro la manera de asignarlo desde una variable personalizada.
Se puede realizar la operacion??
Le agradeceria alguna recomendacion o sugerencia.
Posted by Manuel Acosta | February 15, 2006 9:12 AM
Posted on February 15, 2006 09:12
Is there a quick macro to copy the custom fields that were created in one project to another? Going through each field, importing, then changing the name to be the same is rather annoying.
It would seem that this would be a simple macro, yet I haven't been able to figure it out.
(Note from Jack: You can use the organizer to do this. Try recording a macro of moving the fields over and see what happens.)
Posted by Brad Earle | June 6, 2006 7:29 PM
Posted on June 6, 2006 19:29
Is it possible to copy the overallocation flag from the resource fields to the task fields. What I would like to achieve is highlighting in the Gantt view any tasks that have an overallocated resource assigned to it. I know this can be seen by opening a separate resource graph window but I would like to present it in a printed Gantt. Thanks,
-------------------- Yes it probably is possible, but I'm not sure you would like the results. The general code would be to walk through all the tasks and then the resources on that task and flag any tasks which have an overallocated resource: Sub resoverload() Dim t As Task Dim r As Resource For Each t In ActiveProject.Tasks t.Flag1 = False For Each r In t.Resources If r.Overallocated Then t.Flag1 = True Next Resource Next Task End Sub Once you have this then you can filter or format based on Flag1. -Jack
Posted by Malcolm Manning | March 26, 2008 10:50 AM
Posted on March 26, 2008 10:50
Post a comment
(Comments are moderated to fight SPAM and will be published after I have a chance to approve them. Thanks for waiting.)
Email Address:
Remember personal info?
Comments: (you may use HTML tags for style)
The previous article is Securing Your MS Project Files and Macro Code .
The next article is Just needs a little dog to ride on the tank .
Current articles are in the main index page and you can find a complete list of articles in the archives .
Enable or disable macros in Microsoft 365 files
|
A macro is a series of commands used to automate a repeated task and can be run when you have to perform the task. However, some macros can pose a security risk by introducing viruses or malicious software to your computer.
Warning: Never enable macros in a Microsoft 365 file unless you're sure you know what those macros do and you want the functionality they provide. You don't need to enable macros to view or edit the file. For more info see Protect yourself from macro viruses.
Make a document trusted to enable macros
If you see a security warning when you open a document or try to run a macro, you can choose to make it a trusted document and enable macros. This example is on an Excel workbook.
![ms project vba assignments Macros disabled warning bar](https://support.content.office.net/en-us/media/bfa9a2e4-9717-4722-aee3-ae0c8c0b2fb3.png)
Select Enable Content .
In the Security Warning dialog, select Yes to make the document trusted.
![ms project vba assignments Trusted document security warning](https://support.content.office.net/en-us/media/af55e369-aa85-48bf-a773-f91fbc77d7b2.png)
Macros are now enabled on this document. To revoke a trusted document, you need to clear all trusted documents. For more info, see Trusted documents .
Tip: Rather than enabling macros for each document, you can create a trusted location to store trusted documents. Microsoft 365 will then not check them with the Trust Center. For more info, see Add, remove, or change a trusted location in Microsoft Office .
Change macro settings in the Trust Center
Macro settings are located in the Trust Center. However, if your device is managed by your work or school the system administrator might prevent anyone from changing settings.
Important: When you change your macro settings in the Trust Center, they are changed only for the Microsoft 365 app that you are currently using. The macro settings are not changed for all your Microsoft 365 apps.
Select the File tab and choose Options .
Select Trust Center , and then choose Trust Center Settings .
In the Trust Center , select Macro Settings .
![ms project vba assignments Trust center macro settings](https://support.content.office.net/en-us/media/d512cfe1-8b56-4460-bee1-52a09f09d52c.png)
Make the selections that you want, then select OK .
The following are Macro setting options. Not all apps have the same choices.
Note: The options are slightly different in Excel, we'll call those out as we go.
Disable all macros without notification Macros and security alerts about macros are disabled. In Excel this option is Disable VBA macros without notification and it only applies to VBA macros.
Disable all macros with notification Macros are disabled, but security alerts appear if there are macros present.
Use this setting to enable macros on a case-by-case basis. In Excel this option is Disable VBA macros with notification and it only applies to VBA macros.
Disable all macros except digitally signed macros Macros are disabled, and security alerts appear if there are unsigned macros present. However, if the macro is digitally signed by a trusted publisher, the macro just runs. If the macro is signed by a publisher you haven't trusted yet, you are given the opportunity to enable the signed macro and trust the publisher. In Excel this option is Disable VBA macros except digitally signed macros and it only applies to VBA macros.
Enable all macros (not recommended, potentially dangerous code can run) All macros run without confirmation. This setting makes your computer vulnerable to malicious code. In Excel this option is Enable VBA macros (not recommended, potentially dangerous code can run) and it only applies to VBA macros.
Excel also has a checkbox for Enable Excel 4.0 macros when VBA macros are enabled . If you select this checkbox all of the above settings for VBA macros will also apply to Excel 4.0 (XLM) macros. If this checkbox is not selected XLM macros are disabled without notification.
Trust access to the VBA project object model Block or allow programmatic access to the Visual Basic for Applications (VBA) object model from an automation client. This security option is for code written to automate a Microsoft 365 program and manipulate the VBA environment and object model. It is a per-user and per-application setting, and denies access by default, hindering unauthorized programs from building harmful self-replicating code. For automation clients to access the VBA object model, the user running the code must grant access. To turn on access, select the check box.
Note: Microsoft Access has no Trust access to the VBA project model object option.
Change macro security settings in Excel
Quick start: Create a macro in Excel .
Block suspicious macros in Office on Windows 10 S.
How malware can infect your PC
![ms project vba assignments Facebook](https://support.microsoft.com/images/Facebook-GrayScale.png)
![](http://writinghelp.site/777/templates/cheerup2/res/banner1.gif)
Need more help?
Want more options.
Explore subscription benefits, browse training courses, learn how to secure your device, and more.
![ms project vba assignments ms project vba assignments](https://support.content.office.net/en-us/media/f4e85874-2a1a-438d-9c3c-17b069c454c0.png)
Microsoft 365 subscription benefits
![ms project vba assignments ms project vba assignments](https://support.content.office.net/en-us/media/a9241eee-a729-4513-97b4-5b87c381c21b.png)
Microsoft 365 training
![ms project vba assignments ms project vba assignments](https://support.content.office.net/en-us/media/9e557d93-f803-44df-a274-1282d542cf63.png)
Microsoft security
![ms project vba assignments ms project vba assignments](https://support.content.office.net/en-us/media/fbf6e41b-ddbe-43db-a616-7a8e48d43d18.png)
Accessibility center
Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.
![ms project vba assignments ms project vba assignments](https://support.content.office.net/en-us/media/9255871d-06a6-4de5-9236-5fd7af100c5c.png)
Ask the Microsoft Community
![ms project vba assignments ms project vba assignments](https://support.content.office.net/en-us/media/ccb7c2a6-17dd-4cc3-88b7-8da966e59f59.png)
Microsoft Tech Community
![ms project vba assignments ms project vba assignments](https://support.content.office.net/en-us/media/bcd2fdf1-530a-482f-b96d-5f2f2a49ac66.png)
Windows Insiders
Microsoft 365 Insiders
Was this information helpful?
Thank you for your feedback.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Assignment.Project property (Project)
- 5 contributors
Gets the name of the project containing the Assignment . Read-only String .
expression . Project
expression A variable that represents an Assignment object.
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
Was this page helpful?
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see: https://aka.ms/ContentUserFeedback .
Submit and view feedback for
Additional resources
- Stack Overflow Public questions & answers
- Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
- Talent Build your employer brand
- Advertising Reach developers & technologists worldwide
- Labs The future of collective knowledge sharing
- About the company
Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Get early access and see previews of new features.
How to get the value of a cell in VBA MS Project
I need a code that gives a message depending the different values of some particular cells in a Project, I have already used VBA in Excel, but never in Project, so I don´t know how to do it
I did a code in VBA Excel that do the same thing that I need to do in Project, but I need the code but with the infomation of a Project, but the functions that I use in Excel, are not defined in Project, so I don´t know how to addecuate the code
I am not sure if the way how I get the values of the cells are the only thing that will change about the code, but knowing how to do that, will be a big help
![ms project vba assignments BigBen's user avatar](https://i.sstatic.net/i4sRg.jpg?s=64)
To get the values of a task, use the Task object. In this case you'll want to loop through all of the tasks using the Tasks object (collection of all tasks). It is unclear what task fields you need, but this should get you started:
Note that the Percent Complete and Physical Percent Complete properties return a value from 0 to 100, so don't multiply by 100 later on.
![ms project vba assignments Rachel Hettinger's user avatar](https://i.sstatic.net/7TOmD.jpg?s=64)
- I did the changes you told me, but I can't make it work, I get an error message number 438, it says something like: the object does not support this property or method – DianaLV Commented Oct 23, 2019 at 19:38
- What line is causing the error? BTW: this code is intended to run in MS Project, not Excel. – Rachel Hettinger Commented Oct 23, 2019 at 19:51
- 1 I already make it work! Thank u so much. I think that the error was because I write the tasks in spanish, but the code recognize them only in english – DianaLV Commented Oct 23, 2019 at 20:53
Your Answer
Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more
Sign up or log in
Post as a guest.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .
Not the answer you're looking for? Browse other questions tagged vba ms-project or ask your own question .
- Featured on Meta
- Upcoming sign-up experiments related to tags
- The 2024 Developer Survey Is Live
- Policy: Generative AI (e.g., ChatGPT) is banned
- The return of Staging Ground to Stack Overflow
Hot Network Questions
- What was Jessica and the Bene Gesserit's game plan if Paul failed the test?
- Why focus on T gates and not some other single qubit rotation R making Clifford + R universal?
- What is the history and meaning of letters “v” and “e” in expressions +ve and -ve?
- What does 'bean honey' refer to, in Dorothy L. Sayers' 1928 story
- What is the meaning of this black/white (likely non-traffic) sign seen on German highways?
- Why did the UNIVAC 1100-series Exec-8 O/S call the @ character "master space?"
- Could an Alien decipher human languages using only comms traffic?
- How can the CMOS version of 555 timer have the output current tested at 2 mA while its maximum supply is 250 μA?
- Did the NES CPU save die area by omitting BCD?
- Is there any way to play Runescape singleplayer?
- Why is the Newcomb problem confusing?
- Wrappers around write() and read() and a function to copy file permissions
- Seeking a classification of Bach's preludes (WTC, "little", "great", ...)
- A Fantasy movie with a powerful humanoid being that lives in water
- Am I getting scammed? (Linking accounts to send money to someone's daughter)
- How should I end a campaign only the passive players are enjoying?
- Will a Google Chrome extension read my password
- Should I practise a piece at a metronome tempo that is faster than required?
- Short story in which the main character buys a robot psychotherapist to get rid of the obsessive desire to kill
- How can non-residents apply for rejsegaranti with Nordjyllands Trafikselskab?
- Is a possessive apostrophe appropriate in the verb phrase 'to save someone something'?
- I'm a web developer but I am being asked to automate testing in Selenium
- Which CAS can do basic non-commutative differential algebra?
- How do I perform pandas cumsum while skipping rows that are duplicated in another field?
![](http://writinghelp.site/777/templates/cheerup2/res/banner1.gif)
IMAGES
VIDEO
COMMENTS
Using the Assignments Collection. Use the Assignments property to return an Assignments collection. The following example displays all the resources assigned to the specified task. For Each A In ActiveProject.Tasks(1).Assignments. MsgBox A.ResourceName. Next A. Use the Add method to add an Assignment object to the Assignments collection.
Variant. The number of resource units, expressed as a decimal or percentage, to assign to the task. The default value is 1 or 100%, depending on whether the Show assignment units as a setting is Decimal or Percentage, on the Schedule tab of the Project Options dialog box. If the maximum number of units is less than 1 (or the maximum percentage ...
This code will loop through the resources in the active project and get work hours by resource by week. Dim dteStart As Date. Dim dteEnd As Date. dteStart = #5/24/2021#. dteEnd = #8/2/2021#. Dim res As Resource. Dim a As Assignment. Dim tsvs As TimeScaleValues. Dim tsv As TimeScaleValue.
dim rst as Resource. dim asn as Assignment. dim proj as Project. set proj as Application.Projects.Add. For each row on the input spreadsheet. set tsk = proj.tasks.add. tsk.Name = < task name from spreadsheet > '* this goes OK. proj.Resources.Add (< resource name from spreadsheet > ) '* this goes OK.
For Each a In t.Assignments 'change the following line to use 'for a different custom field a.Text5 = t.Text5 Next a End If Next t End Sub. Pretty easy. This one should have no problems because each assignment only has a single task that it references. However, going the other way could be a problem as each task can have several assignments.
MS Project VBA - Add Assignment in Consolidated file Is there ANY way to add an Assignment from a macro within a consolidated Project file? I have multiple files consolidated/checked out and want to change a Resource Assignment for a specific Task. The Assignments.Add method seems to require a Task ID.
In this article. Gets an Assignments collection representing the assignments for the resource. Read-only Assignments.. Syntax. expression.Assignments. expression A variable that represents a Resource object.. Support and feedback. Have questions or feedback about Office VBA or this documentation?
Jul 17 2022 05:24 PM. wjls20854, Over the years I've used three methods for transferring data from Project to Excel. 1) Gather all the Project data into arrays, open an instance of Excel, dump the arrays into the Worksheet, format as necessary and close. 2) Open an instance of Excel, pre-format the Worksheet, on the fly read and write Project ...
If you want to change an existing assignment, you first must delete the assignment and then use the add method. Or, if you just want to change the units assignment of an existing assignment, the following syntax will work. ActiveProject.Tasks (1).Assignments (1).Units=0.6. Note: you would need a loop of all that tasks assignments to determine ...
Hi, (MS Project 2003) I want to programmatically set the Text1 field for all assignments, including those that are unassigned. (You might think there's no such thing as an unassigned assignment, but if you add column Text1 to, say the resource usage view you will find that you can enter values for all assignments, including those where the resource is unassigned, and all the values are retained.
The difference in the two values is a power of 2, 2 to the 20th to be exact (i.e. 2^20). Knowing that value, you can introduce a "fudge factor" when reading the assignment unique ID with VBA. Another approach is to copy the Assignment Unique ID to a number field (e.g. Number1). If you use VBA to read the number field, it will show the correct ...
In this article. Represents an assignment for a task or resource. The Assignment object is a member of an Assignments or an OverAllocatedAssignments collection.. Example. Using the Assignment Object. Use Assignments (index), where index is the assignment index number, to return a single Assignment object. The following example displays the name of the first resource assigned to the specified task.
Gets or sets the actual work (in minutes) for the assignment. Read/write Variant. Syntax. expression. ActualWork. expression A variable that represents an Assignment object. Support and feedback. Have questions or feedback about Office VBA or this documentation?
Assigning resources manually per task is time consuming. Not every resource is assigned to each task, and each resource has varying hours within a task. Example- task 1 may have R1 30 hours, R2 10 hours, R3 5 hours, with the resources working concurrently, for no more than the highest number of hours assigned for this task, (30 hours). Task 2 ...
Change path as applicable. appProj.FileOpen "C:\MS Project.mpp" Set aProg = appProj.ActiveProject appProj.Visible = True '~~> Now you have the MPP file opened, rest of the code goes here End Sub I have successfully opened MPP file but I want to copy paticular task data to Excel.But I have no idea how to do it.My MPP has many tasks. Please Help.
Trust access to the VBA project object model Block or allow programmatic access to the Visual Basic for Applications (VBA) ... This security option is for code written to automate a Microsoft 365 program and manipulate the VBA environment and object model. It is a per-user and per-application setting, and denies access by default, hindering ...
The Task Form is the easiest way to enter work when assigning resources. Split your screen using the Details choice in the Split group on the View tab. This will show the Task Form in the lower pane. Select the task in the Gantt chart, click the drop down in the Task Form underneath Resource Names.
The names of the resources to be assigned, removed, or replaced in the selected tasks. Note Project will not assign a resource if thousands separators or decimal separators are included in the unit values. Operation. Optional. Long. If Operation is omitted, Project assigns the resources to the selected tasks. The default value is pjAssign.
In this article. Gets the name of the project containing the Assignment.Read-only String.. Syntax. expression.Project. expression A variable that represents an Assignment object.. Support and feedback. Have questions or feedback about Office VBA or this documentation?
To get the values of a task, use the Task object. In this case you'll want to loop through all of the tasks using the Tasks object (collection of all tasks). It is unclear what task fields you need, but this should get you started: