none
Modify Custom Properties in word 16 RRS feed

Answers

  • Hi Aakash Patil,

    If you are looking for an example using VBA then you can refer example below.

    Set myRange = ActiveDocument.Content 
    myRange.Collapse Direction:=wdCollapseEnd 
    For Each prop In ActiveDocument.CustomDocumentProperties 
     With myRange 
     .InsertParagraphAfter 
     .InsertAfter prop.Name &; "= " 
     .InsertAfter prop.Value 
     End With 
    Next

    Reference:

    Document.CustomDocumentProperties Property (Word)

    If you want example in C# or VB then you can refer example and link below.

      void TestProperties()
            {
                Microsoft.Office.Core.DocumentProperties properties;
                properties = (Office.DocumentProperties)this.CustomDocumentProperties;
    
                if (ReadDocumentProperty("Project Name") != null)
                {
                    properties["Project Name"].Delete();
                }
    
                properties.Add("Project Name", false,
                    Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString,
                    "White Papers");
            }
    
            private string ReadDocumentProperty(string propertyName)
            {
                Office.DocumentProperties properties;
                properties = (Office.DocumentProperties)this.CustomDocumentProperties;
    
                foreach (Office.DocumentProperty prop in properties)
                {
                    if (prop.Name == propertyName)
                    {
                        return prop.Value.ToString();
                    }
                }
                return null;
            }

    Reference:

    How to: Create and Modify Custom Document Properties

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Aakash Patil Thursday, March 29, 2018 4:51 AM
    Tuesday, March 20, 2018 5:08 AM
    Moderator

All replies

  • Hi Aakash Patil,

    If you are looking for an example using VBA then you can refer example below.

    Set myRange = ActiveDocument.Content 
    myRange.Collapse Direction:=wdCollapseEnd 
    For Each prop In ActiveDocument.CustomDocumentProperties 
     With myRange 
     .InsertParagraphAfter 
     .InsertAfter prop.Name &; "= " 
     .InsertAfter prop.Value 
     End With 
    Next

    Reference:

    Document.CustomDocumentProperties Property (Word)

    If you want example in C# or VB then you can refer example and link below.

      void TestProperties()
            {
                Microsoft.Office.Core.DocumentProperties properties;
                properties = (Office.DocumentProperties)this.CustomDocumentProperties;
    
                if (ReadDocumentProperty("Project Name") != null)
                {
                    properties["Project Name"].Delete();
                }
    
                properties.Add("Project Name", false,
                    Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString,
                    "White Papers");
            }
    
            private string ReadDocumentProperty(string propertyName)
            {
                Office.DocumentProperties properties;
                properties = (Office.DocumentProperties)this.CustomDocumentProperties;
    
                foreach (Office.DocumentProperty prop in properties)
                {
                    if (prop.Name == propertyName)
                    {
                        return prop.Value.ToString();
                    }
                }
                return null;
            }

    Reference:

    How to: Create and Modify Custom Document Properties

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Aakash Patil Thursday, March 29, 2018 4:51 AM
    Tuesday, March 20, 2018 5:08 AM
    Moderator
  • Hi Aakash,

    The VBA example provided by Deepak, only shows code to use your custom documentproperties. If you need to modify them, have a look at the example in this URL

    https://wordmvp.com/FAQs/MacrosVBA/MixedDocProps.htm 

    • Marked as answer by Aakash Patil Thursday, March 29, 2018 4:51 AM
    • Unmarked as answer by Aakash Patil Thursday, March 29, 2018 4:51 AM
    Saturday, March 24, 2018 1:05 AM