HRESULT E_FAIL from COM component at Microsoft.Office.Core.Document Property Add
-
Tuesday, December 11, 2012 12:06 PM
I'm doing a AddIn for MS Project and one thing necessary is to add a custom document property.
Here is the code:
Dim docProperty = CType(Globals.ThisAddIn.Application.ActiveProject.CustomDocumentProperties, Office.DocumentProperties) docProperty.Add("Project Code", False. Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString, ComboBox1.SelectedValue )In the function docProperty.Add() Throw this error:
Error HRESULT E_FAIL has been returned from a call to a COM component
ErrorCode: -2147467259
StackTrace:
at Microsoft.Office.Core.DocumentProperties.Add(String Name, Boolean LinkToContent, Object Type, Object Value, Object LinkSource)
at CatCpoIntegSicatt.CatClfEscolhaProjeto.bntOk_Click(Object sender, EventArgs e) in C:\ATTPS\DES\SIN\CAT\07.00\CAT\Integracao\CatCpoIntegSicatt\CatClfEscolhaProjeto.vb:line 127
TargetSite:{Microsoft.Office.Core.DocumentProperty Add(System.String, Boolean, System.Object, System.Object, System.Object)}
All Replies
-
Tuesday, December 11, 2012 3:12 PMModerator
Your code isn't making any sense. Shouldn't it be more like:
Dim docProperty As Office.DocumentProperty
docProperty = [ProjectDocumentObject].Add('params here)I've never worked with Project, so I don't know what the "document container" for a DocumentProperty would be, but you get the idea?
Cindy Meister, VSTO/Word MVP, my blog
-
Wednesday, December 12, 2012 2:30 AMModerator
Hi Guiherme,
Thanks for posting in the MSDN Forum.
I hope following code can help you.
Imports Microsoft.Office.Tools.Ribbon Public Class Ribbon1 Private Sub Ribbon1_Load(ByVal sender As System.Object, - ByVal e As RibbonUIEventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) _ Handles Button1.Click Dim mpApp As MSProject.Application Dim mpPjt As MSProject.Project Dim oCPs As Object Dim parameters As Object() mpApp = Globals.ThisAddIn.Application mpPjt = mpApp.ActiveProject oCPs = mpPjt.CustomDocumentProperties parameters = New Object() {"MyAttribute", False, _ Office.MsoDocProperties.msoPropertyTypeString, "Just a test"} oCPs.GetType().InvokeMember("Add", Reflection.BindingFlags.Default Or _ Reflection.BindingFlags.InvokeMethod, Nothing, oCPs, parameters) End Sub End ClassIt works fine on my side.
Have a good day,
Tom
Tom Xu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
Wednesday, December 12, 2012 1:41 PM
Hi Cindy,
Thanks for response. My code make sense, but I think i didn't make a good question.
This code I took from Microsoft Reference as you can see in this link.I found the answer and will post it.
-
Wednesday, December 12, 2012 1:44 PM
Thanks everybody ,
I found the answer for this problem.
This error occours when try to add a propertie who already exist !
I did a function to verify if this property doesn't exist before add and now works fine!
- Edited by Guilherme Batista Wednesday, December 12, 2012 1:48 PM
- Marked As Answer by Guilherme Batista Wednesday, December 12, 2012 1:49 PM
-
Wednesday, December 12, 2012 1:51 PM
Tom,
Your answer works fine, thanks, but I also find the solution to my problem using my code.
Thanks a lot anyway.
I've posted the solution below.

