VBA support

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
Roman55
Posts: 10
Joined: Tue Mar 26, 2013 11:29 am

VBA support

Post by Roman55 »

Hello

Is there a macros support for Excel97? The sample code from BIFF_VBA5.pas works but Excel 2003 crashes trying to open output file.

Code: Select all

  xlsRW.BIFF.ReadMacros := true;
  xlsRW.VBA.EditVBA := True;
  // Add a VBA module and a procedure.
  with xlsRW.VBA.AddModule('Module1',vmtMacro) do begin
    Source.Text :=
    'Sub MyTestMacro()' + #13#10 +
    'MsgBox "MyTestMacro executed"' + #13#10 +
    'End Sub';
  end;

  // Add a button control.
  with xlsRW.BIFF.Sheet[0].ControlsObjects.Buttons.Add do begin
    Text := 'Macro test';
    Col1 := 2;
    Row1 := 4;
    Col2 := 3;
    Row2 := 5;
    // The name of the macro must match the previous added macro procedure.
    MacroName := 'MyTestMacro';
  end;
By the way, there is an odd thing: "ReadMacros := true" is necessary to write macros. Otherwise, xlsRW.VBA is Nil.
Post Reply