HotXLS Docs

TXLSVBAProject class

Unit: lxVBA
Represents a parsed VBA project stored inside a classic XLS workbook. Obtain an instance via IXLSWorkbook.VBAProject or TXLSXWorkbook.ParsedVBAProject. If the workbook contains no VBA storage both properties return nil.
The project holds a list of TXLSVBAModule items — one per module stream found in the VBA storage. Modules are indexed 1 to Count. The default array property lets you write Project[1] without naming the property explicitly.

Properties

Count property — Number of VBA modules in the project (read-only).
Item[index: Integer] property — Returns the TXLSVBAModule at the 1-based position index. This is the default array property.

Example

Read the source code of every module in an XLS workbook that contains macros.

var
  Workbook: IXLSWorkbook;
  Project: TXLSVBAProject;
  i: Integer;
begin
  Workbook := TXLSWorkbook.Create;
  Workbook.Open('C:\MacroBook.xls');
  Project := Workbook.VBAProject;

  if Project <> nil then
    for i := 1 to Project.Count do
      Memo1.Lines.Add(Project[i].Name + ': ' + Project[i].SourceCode);
end;

See also