I wish to output a spreadsheet (from scratch) that includes VBA code to do something when the user changes a cell in the spreadsheet. I've included a very basic example console app below but I cannot get it working. Please help.
program VBATest;
{$APPTYPE CONSOLE}
uses
SysUtils,
XLSReadWriteII2,
XLSVBA2;
var xls: TXLSReadWriteII2;
begin
xls := TXLSReadWriteII2.Create(nil);
try
xls.Filename := 'C:\VBA.xls';
xls.VBA.EditVBA := True;
with xls.VBA.AddModule(xls.Sheet[0].Name, vmtDocument).Source do
begin
Add('Private Sub Worksheet_Change(ByVal Target As Range)');
Add(' MsgBox "Something Changed"');
Add('End Sub');
end;
xls.Write;
finally
FreeAndNil(xls);
end;
end.