Forum Discussion
Hammock Tasks and VBA
Hello,
I have two questions about Hammock Tasks and VBA.
Creating the Task
I have recorded a macro and had a look at how it is set up, the macro records the actual Copy and Paste steps.
Is there any other way of doing this in VBA? Such as referring to Task variables. I think Copy and Paste (which relies on Start and Finish being displayed) is limited.
Determining if a task is a hammock task
This one is actually the main question
When I loop through the tasks such as
For each oTask in ActiveProject.Tasks
xxxx
Next oTask
Is there anyway of determining if the objTask.Start and objTask.Finish fields have links in them?
If they both do then I can assume that it is a hammock task
Thank You
First of all I should note that Paste Links are prone to corruption. They use dated DDE protocol for OLE links that I found to be "shakey" under older versions of Project and as I noted, doesn't appear to work correctly under Windows 10 (at least for me), although it may work under Windows 10 if applications are set to run as admin.
Using Application.ObjectLinks will open the Edit Links window and that will show all the OLE links in the current file. Unfortunately the link data presented is not very useful (i.e. only gives the project name and a link number). The "source" task can be identified by selecting a link and using the Open Source button but there is no "destination" info that identifies which task is the destination. You might be interested in reading this Wiki article:
https://social.technet.microsoft.com/wiki/contents/articles/32040.ms-project-hammock-tasks.aspx
John
5 Replies
- John-projectSilver ContributorAs far as creating a paste link using VBA, there are no direct object methods made available. Since the paste link operation works with foreground objects (i.e. selected items) you would need to first do a copy of the source field (i.e. EditCopy) and then use the Application.DDEPasteLink method for both start and finish of the hammock task.
As far as detecting which tasks are hammock tasks, the best you can do is to query the EditLinks window using the Application.ObjectLinks Method. If there are any paste links present in the file, the window will open, otherwise you will get an error which you can trap. As noted, the ObjectLInks Method is at application level and not available at task level.
Interestingly I cannot get hammock tasks to work with Project 2019. A hammock task can be created and the first time it will "hammock" as desired, but it will not update when the source or destination fields are changed, either directly in the view (i.e. manual update of Start and/or Finish fields) or via the EditLinks window. It works fine in Project 2010 and earlier.
Hope this helps.
John- Gilgamesh1964Brass Contributor
Thank you for taking the time to respond.
On creating the tasks I will just have to live with the copy/paste method - c’est la vie
I have had a quick play with the Application.ObjectLinks method.
So this gives me a binary yes/no on whether links exist, so there is no way to query the links themselves to find to/from data?
I was hoping to find a way of identifying which specific tasks were the hammock tasks

- John-projectSilver Contributor
First of all I should note that Paste Links are prone to corruption. They use dated DDE protocol for OLE links that I found to be "shakey" under older versions of Project and as I noted, doesn't appear to work correctly under Windows 10 (at least for me), although it may work under Windows 10 if applications are set to run as admin.
Using Application.ObjectLinks will open the Edit Links window and that will show all the OLE links in the current file. Unfortunately the link data presented is not very useful (i.e. only gives the project name and a link number). The "source" task can be identified by selecting a link and using the Open Source button but there is no "destination" info that identifies which task is the destination. You might be interested in reading this Wiki article:
https://social.technet.microsoft.com/wiki/contents/articles/32040.ms-project-hammock-tasks.aspx
John