How to decide if an excel file has got VBA code in it ?

S

Sujit

Guys,

I am looking for a way to decide whether an excel file has got some VBA code
in it?
How can i achieve this without opening the excel file and macros. I have a
set of excel files in my organisation and need to filter all the excel files
which has got some VBA code inside it. I am probably looking for creating a
tool in c# to do this automation. So if anyone of you have any knowledge of
c# classes to access office components like excel that will be helpful.

Many Thanks in advance,
 
Z

ZSvedic

Guys,

I am looking for a way to decide whether an excel file has got some VBA code
in it?
How can i achieve this without opening the excel file and macros. I have a
set of excel files in my organisation and need to filter all the excel files
which has got some VBA code inside it. I am probably looking for creatinga
tool in c# to do this automation. So if anyone of you have any knowledge of
c# classes to access office components like excel that will be helpful.

Many Thanks in advance,

This is the case:

Every XLS file is in fact OLE2 Compound File/Document, also called "
COM/OLE structured storage" (http://en.wikipedia.org/wiki/
Structured_storage). That file internally contains streams of data
with various parts of XLS file. If there is a stream called
"_VBA_PROJECT_CUR" inside XLS file, you can be sure it contains VBA
code. In other words, open file as OLE2 Compound Document and check
stream names for macro stream name. In C# you can open OLE2 Compound
Documents using our GemBox.CompoundFile component (http://
www.gemboxsoftware.com/CompoundFile.htm, Free version is size
limited). There you also have viewer for OLE2 Compound Files.

For new XLSX file format, check is trivial. If the file contains
macros, it has extension .XLSM.

If you want to remove Macros from XLS file, you can use our
GemBox.Spreadsheet Excel component (http://www.gemboxsoftware.com/
GBSpreadsheet.htm) and deselect Preserve when loading the file (http://
www.gemboxsoftware.com/help/GemBox.Spreadsheet.XlsOptions.html).

And, of course, you can use Excel Automation/interop, which has its
drawbacks (http://www.gemboxsoftware.com/GBSpreadsheet.htm#Automation)
but it supports ALL features of Excel file formats.

Hope I helped,

-- Zeljko
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top