none
How to extract the Microsoft Word Document property RRS feed

  • Question

  • I am helping to design a tool to extract the document property data from microsoft before a file is saved or converted into other form. Does anyone knows what method we can use to extract the data?

    Thanks so much!

     
    Saturday, January 10, 2015 11:52 PM

Answers

  • Hi,

    Thanks for posting in MSDN forum.

    According to the descrption, you want to get the document property from the Word document.

    We can use the BuiltInDocumentProperties property of a  Microsoft.Office.Interop.Word.Document to get the document properties.

    And here is an sample that get the author form the specific document for your reference:

     string fileName = @"C:\Users\UserName\Desktop\Doc1.docx";
                Word.Application word = new Word.Application();
                Word.Document doc = word.Documents.Open(fileName,Type.Missing,true);
                Console.WriteLine(String.Format("Author:{0}", doc.BuiltInDocumentProperties[WdBuiltInProperty.wdPropertyAuthor].Value));
                doc.Close(WdSaveOptions.wdDoNotSaveChanges);
                word.Quit();
    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 14, 2015 3:03 AM
    Moderator
  • In addition to Fei's answer this is a VBA snippet you can use (don't know if you are using VSTO or VBA).

    Sub ClearCDP

    Dim CDP as DocumentProperty

    For Each CDP in ActiveDocument.CustomDocumentProperties '-- user created document properties

      CDP.Value=""

    Next

    End sub

    '-.... For built in properties you can check the built in docprops as FEI stated

    hth


    Maurice

    Wednesday, January 14, 2015 7:50 AM

All replies

  • Hi,

    Thanks for posting in MSDN forum.

    According to the descrption, you want to get the document property from the Word document.

    We can use the BuiltInDocumentProperties property of a  Microsoft.Office.Interop.Word.Document to get the document properties.

    And here is an sample that get the author form the specific document for your reference:

     string fileName = @"C:\Users\UserName\Desktop\Doc1.docx";
                Word.Application word = new Word.Application();
                Word.Document doc = word.Documents.Open(fileName,Type.Missing,true);
                Console.WriteLine(String.Format("Author:{0}", doc.BuiltInDocumentProperties[WdBuiltInProperty.wdPropertyAuthor].Value));
                doc.Close(WdSaveOptions.wdDoNotSaveChanges);
                word.Quit();
    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 14, 2015 3:03 AM
    Moderator
  • In addition to Fei's answer this is a VBA snippet you can use (don't know if you are using VSTO or VBA).

    Sub ClearCDP

    Dim CDP as DocumentProperty

    For Each CDP in ActiveDocument.CustomDocumentProperties '-- user created document properties

      CDP.Value=""

    Next

    End sub

    '-.... For built in properties you can check the built in docprops as FEI stated

    hth


    Maurice

    Wednesday, January 14, 2015 7:50 AM
  • Hi. Thank you for teaching me that! Currently I want to write a macro to extract the document property into a text file when the file is converted into PDF form! Can you tell me how to do that?
    Friday, January 23, 2015 5:33 AM
  • Hi,

    >>Currently I want to write a macro to extract the document property into a text file when the file is converted into PDF form! Can you tell me how to do that?<<

    If you want to write the string into text file, we can use open and write statement in VBA. Also here is a samlpe that write "Hello Word" into a text file:

    Sub WriteFile()
    Open "c:\users\UserName\desktop\Support.log" For Append As #1
    Write #1, "Hello World"
    Close #1
    End Sub

    You can get more detail about writing file from link below:
    Write # Statement

    However, as far as I know, there is no such event in Word we can detect the uses converted the document into PDF format. You may consider using Application.DocumentBeforeSave Event or you can submit the feedback from link below if you want Word application to support this event:
    Submit Feedback - Microsoft Support

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, January 27, 2015 9:49 AM
    Moderator