How to read VBA code from macro-enabled document(.DOCM) using openXML in C# ?


  • I need to read VBA code which is included in macro enabled document(.DOCM) file using openXML in c#.

    I have tried following code but it returns weird string.

    using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(filePath, false))

           VbaProjectPart vbaPart = wordDoc.MainDocumentPart.VbaProjectPart;

           Stream stream = vbaPart.GetStream();

           using(StreamReader reader = new StreamReader(stream,Encoding.UTF8))


              string vbaData = reader.ReadToEnd();



    Any help would be appreciated.


    mercredi 13 juin 2018 12:04


  • Hello Sanjay_15,

    As far as I know, the VBA project is stored in a binary format file and OpenXML does not provide the any function to export code from it. I think we could not read the VBA code using OpenXML.

    Best Regards,


    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

    • Marqué comme réponse Sanjay_15 jeudi 14 juin 2018 10:16
    jeudi 14 juin 2018 07:48