Check the MS office files(word, excel,ppt, access etc.) are macro enabled (embedded malicious codes) or not using C#/JAVA SCRIPT RRS feed

  • Question

  • I have some Office files... I want to upload these files into Data Base... Before uploading i want to check the files are macro enabled or not... Expecting the solution in java script... I have tried with the following file extensions.. `".docm",".dotm",".xlm ",".xltm",".xlsm",".xla",".xlam",".pptm",".potm",".ppsm",".sldm",".ppam",".accde"` but i need to know any other way to find the solution in JS or C#, by processing the file content and check any programming contents inside it.. these are the codes i tried... var extnsnArray=[".docm",".dotm",".xlm",".xltm",".xlsm",".xla",".xlam",".pptm",".potm",".ppsm",".sldm",".ppam",".accde"] var extnsn = $(file).attr('extension'); if (extnsnArray.indexOf(extnsn) > -1) { // file is macro enabled } else { // file is not macro enabled } Also i want to know the chance of embedding malicious codes inside a non macro enabled office files

    (.doc,.ppt,.xlsx etc.)

    Thursday, May 18, 2017 5:41 AM

All replies

  • Hello,

    Office JS API now doesn't provide any feature to access the macro in the file.

    Using C#, you could automate Office application to open these file and then access the VBE to check if there is macro. You could also use Open XML SDK to check if there is macro, but Open XML SDK works for Open XML format files, it doesnt support old file format like .xls .doc.

    In my opinion, I would suggest you use Open XML. To access the VBProject using XML, I suggest you download the Open XML SDK Tool from

    You could create two files. One has macro and the other doesn't have macro in it. Then you could use Open XML SDK Tool compares the two files and generate c# code.

    If you want to automate Office to check file using Office object model, you need to add reference "Microsoft Visual Basics for Applications Extensibility 5.3", then you could access its VBE and VBProject. Please visit Visual Basic Extensibility Reference for more information about the objects.



    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

    Wednesday, May 24, 2017 7:14 AM