0

WorkbookBeforeClose event of Excell Application has 2 parameters: (Workbook Wb, ref bool Cancel) . I want to add Excel.Application excellApp like third paramater into that event. Here is the way to pass another parameter to event. I tried:

excelApp.WorkbookBeforeClose += new AppEvents_WorkbookBeforeCloseEventHandler((wb, c) => mamed(wb, c, excelApp ));

But I get error like parameter 2 must be declared with the 'ref' keyword. I also added 'ref' keyword, but there is not any result.

How can I sole this issue?

Community
  • 1
  • 1
Jeyhun Rahimov
  • 3,769
  • 6
  • 47
  • 90

1 Answers1

1

You need to declare the cancel parameter (c) with the ref keyword:

excelApp.WorkbookBeforeClose += new Excel.AppEvents_WorkbookBeforeCloseEventHandler(
    (Excel.Workbook wb, ref bool c) => mamed(wb, c, wb.Application)
    );
Joe
  • 122,218
  • 32
  • 205
  • 338
  • One question please: my mamed() event return "object". What should I return there? In that method I do application closing operatrions only. – Jeyhun Rahimov Mar 05 '14 at 07:56
  • 1
    @JhoonBey - the return value is ignored, so if you're not using it anywhere else you can return anything (e.g. null), or change the method signature to void. – Joe Mar 05 '14 at 08:01