How to add code to worksheet not module

Oct 9, 2013 at 12:38 AM
Edited Oct 9, 2013 at 12:40 AM
Howdy. Fairly new to C# so forgive the ignorance.
In all the examples I've seen and used the VBA code has always been a new module, but how do I add code the sheet itself to call the macro created? Here's partial code up to the point where I need to add it. Any help would be greatly appreciated.
   ExcelPackage pck = new ExcelPackage();
        //Create the worksheet
        ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Whse");
        //Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
        ws.Cells["A2"].LoadFromDataTable(dt, true);
        ws.Column(2).Style.Numberformat.Format = "0";
        //Set title of spreadsheet
        ws.Cells["A1"].Value = "Requested RTV (" + ID.ToString() + ") Style Listing " + Request.QueryString["Name"];                            
        ws.SetValue("N2", "Dlb Click to Save to DB");           
        //Now add double click code...
        var sb = new StringBuilder();
        sb.AppendLine("Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)");
        sb.AppendLine("If Target.Address = \"$N$2\" THEN");
        sb.AppendLine("Call UpdateFinalUnits");
        sb.AppendLine("End If");
        sb.AppendLine("End Sub");
Add code to the worksheet