Harald
Harald

Reputation: 3

Add file to MS-Project task note field with VBA

I am trying to store details on specific milestones in an MS Project file (I am using the MS Project Online Desktop Client) by adding the information into the Notes field of the task (as normal custom text fields are limited to 255chars), but have issues with keeping the formatting. The Notes field also allows adding any type of files (e.g. Word or Excel) as and object, which could be an excellent solution for me, but when using the MS Project Macro recorder the action of adding an object is not recorded.

Hence my question: Is there any possibility in VBA to add a file to the Notes field of a task and later retrieve it?

Any help would be greatly appreciated.

Best, Harald

Upvotes: 0

Views: 290

Answers (2)

Harald
Harald

Reputation: 3

Thanks a lot for the fast response and the warning! I did a bit more digging and I am reasonably sure it cannot be done with VBA. What I have now done is to put an HTML-like string into the notes, containing the data from Excel on the details of my deliverables.

<DELIVERABLEINFO><OBJECTIVE>The Project Change Management Plan defines and documents the change process for a project.</OBJECTIVE><TOC>to be defined</TOC><INFO>to be defined</INFO></DELIVERABLEINFO>

When later generating the Excel file from MS-Project I then parse the string and fill the specific fields again. Works quite nice, but what I found is that while the string can be generated directly from the Excel cell content, when putting it back from the Note to the Excel file I need to process it with the below function to have line breaks shown again.

Function StringFromNoteToExcel(strNote As Variant) As String
        On Error GoTo StringFromNoteToExcel_Error
        StringFromNoteToExcel = Trim(Replace(strNote, vbCr, vbLf))
        StringFromNoteToExcel = Replace(StringFromNoteToExcel, vbVerticalTab, vbLf)
        StringFromNoteToExcel = Replace(StringFromNoteToExcel, vbTab, vbLf)
          
        On Error GoTo 0
        Exit Function

StringFromNoteToExcel_Error:

        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure StringFromNoteToExcel, line " & Erl & "."

End Function

It doesn't allow any fancy formatting, but at least keeps the structure and you can still add notes outside the HTML like block I added.

Thanks again! Harald

Upvotes: 0

Kenny Arnold
Kenny Arnold

Reputation: 378

I'm not certain there is a way to do that in code. It seems the Notes property of the task object only accepts string data. Even if there is a way to attach a file as the note, I'm going to highly advise against it because it can cause your project file to become corrupt. I'm including an image from this article:

enter image description here As someone who has used MS Project for a long time, I've seen this corruption happen first hand and it's quite literally the worst thing that can happen to your project file. A better alternative would be to put these files on a shared network location and just reference the path to the file you want, which you can do in VBA code via the Notes property of the task.

Upvotes: 1

Related Questions