Problem with macro detection

Hello!

I’ve testing the HasMacro property after opening an word document.

But with the following document it doesn’t work.
Becasue, the word document definitly has macros, but the hasmacro property says no.

May you tell me whats the problem?

Hi
Thank you for your interest in Aspose products. I can’t see VBA project in this document. HasMacros property returns true if the document has a VBA project (macros).
Best regards.

but I’ve added an macro within microsoft word, and thought that there must be a vba project after adding it.

may you given me an example word document with an macro, which is working?

Thanks.

Hi
See the attached file. I have created macros using VBS editor.
Best regards.

Thanks for the sample.

I think I created the macro the same way.
May be there is a problem because, I’ve created the doc file with office 2007?

I’ve found the problem, now it works. Thank you.

Hi,

What is your solution?

Aspose.Words.Document document = new Aspose.Words.Document("macrofile.docx");
bool macro = document.HasMacros;

the file has macro…but macro is false.

Thanks,
-Surendra

@andy.a.kuan.wellsfar,

Thanks for your inquiry. Please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.

Hi,

This zip file contains word file and has micro. how do i detect macro from aspose.word?

macro_doc.zip (9.8 KB)

Thanks in advance…

-Surendra

@andy.a.kuan.wellsfar,

Thanks for sharing the document. Your document does not contains the macros. The Document.HasMacros returns the correct value.

Hi There,

It has two Macros. just downloaded same file and checked that.

macro_image.PNG (49.4 KB)

Please double check again.

My code is here:

Aspose.Words.Document doc = new Aspose.Words.Document(stream);
bool hasMarco = doc.HasMacros;

This document has marco into it but HasMacros property always return false.

Thanks

@andy.a.kuan.wellsfar,

Thanks for your inquiry. Please share the MS Word version that you are using. We checked it with MS Word 2010 and 2016 and have not found the macros. Please check the attached screenshots. ms word 2010.png (77.9 KB)
ms word 2016.png (27.0 KB)

Hi Thanks for your reply…

Our client can upload MS word 2003, 2007, 2010, and i believe that all version support macro. I am pretty much sure you can create marcos in all those version. Go to view menu and in Macro button in Ribbon bar.

i have created macros and when i used HasMacros property . it always returns false. not quite sure that why it is like that.

macro_file.PNG (98.1 KB)
macro_file.PNG (98.1 KB)

please check these two files. one has macro and another is just image.

Thanks,

@andy.a.kuan.wellsfar,

Thanks for your inquiry. The file format of your document is DOCX and this format does not contains the macro. The file format DOCM contains the macro. Please execute the following code snippet to check the file format of “macro_doc.docx”.

Document doc = new Document(MyDir + "macro_doc.docx");
Console.WriteLine(doc.OriginalLoadFormat);

The macros listed at your end are in default template document. Please select the option “Macros in” to check the macros in your document. Please check this image. Macros in.png (26.7 KB)

If your document contains the VBA code, the code will under Project (Macro_doc). Please check this image Macro_doc.png (18.1 KB)

Moreover, if you create macro and save the document (macro_doc.docx), you will get VBA project message to save DOCX to DOCM file format. Please check this image. VBA project message.png (27.3 KB)

Hope this clears the detail of macros. Please let us know if you have any more queries.

Thanks for your clarification…!!!