Forum


Replies: 3   Views: 752
How can i detect if a doc has macros in it
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by akhil  · 15-07-2022 - 20:55

I wanted to check if the uploaded word document has macros in it. The document has the extension (.doc). How can I perform this using phpdocx?

Posted by admin  · 16-07-2022 - 08:31

Hello,

Macros can be detected by phpdocx when using DOCX documents. In the case of the old DOC documents, maybe you can transform DOC to DOCX using the conversion plugin (https://www.phpdocx.com/api-documentation/format-conversion/convert-Word-docx-into-pdf-with-PHP) and then use phpdocx to check if the DOCX contains macros.

If you send to contact[at]phpdocx.com a DOC document sample you are using, we'll check it.

Regards.

Posted by akhil  · 19-07-2022 - 14:18

Thank you. What method in phpdocx can be leveraged to detect macros in a DOCX file?

Posted by admin  · 19-07-2022 - 14:32

Hello,

The easiest approach is using the getWordFiles method to check if the DOCX/DOCM file contains a macro file. For example:

$docx = new CreateDocxFromTemplate('fileMacros.docm');

$contentsVbaData = $docx->getWordFiles('word/vbaData.xml');
$contentsVbaProjectData = $docx->getWordFiles('word/vbaProject.bin');

if ($contentsVbaData || $contentsVbaProjectData) {
    echo 'Macro file found' . PHP_EOL;
}

Regards.