Returns true if Workbook contains VBA code
Syntax
function VBADefined:boolean;
Description
Use VBADefined before overwriting an existing workbook when
your application must preserve files that contain macros. The method is
a read-only check; it does not create, remove, or edit VBA modules
In the classic XLS facade, a True result means that the workbook has a
VBA project stream. Save the file with an Excel format that can keep VBA
content, and avoid exporting it to text, HTML, or RTF if macro
preservation is required
Example
This example opens an existing workbook and checks whether it contains
VBA code before saving it
var
Workbook: IXLSWorkbook;
begin
Workbook := TXLSWorkbook.Create;
try
Workbook.Open('C:\Reports\Template.xls');
if Workbook.VBADefined then
ShowMessage('This workbook contains VBA code.');
Workbook.SaveAs('C:\Reports\TemplateCopy.xls');
finally
Workbook := nil;
end;
end;
See also