HotXLS Docs

TXLSVBAModule class

Unit: lxVBA
Represents a single VBA module within a TXLSVBAProject. Each module exposes its name and decompressed source code. Obtain a module via TXLSVBAProject.Item[index] (1-based).

Properties

Name property — The module name as stored in the VBA project directory stream. Read-only.
SourceCode property — The decompressed VBA source text of the module, decoded to a Unicode string using the project's code page. Read/write — setting this property replaces the in-memory source text.

Example

List the name and first line of source code for every module in the project.

var
  Project: TXLSVBAProject;
  Module: TXLSVBAModule;
  i: Integer;
  FirstLine: WideString;
begin
  Project := Workbook.VBAProject;

  if Project = nil then Exit;

  for i := 1 to Project.Count do
  begin
    Module := Project[i];
    FirstLine := Copy(Module.SourceCode, 1, 80);
    ShowMessage(Module.Name + ': ' + FirstLine);
  end;
end;

See also