Firing macro OnChange event

I am opening a spreadsheet that has a macro that fires when a cell value changes.

   Sub Worksheet_Change(ByVal Target As Range)
...
End Sub

The code in the macro changes the format in the cell, such as changing the cell color to blue. In my code, I am making changes to that spreadsheet (inserting rows and updating cells in those rows).

The event does not seem to fire when I make a change to cells. My code looks like this...

using var excelEngine =new ExcelEngine();
var application = excelEngine.Excel;
using FileStream inputStream =new(fileName,FileMode.Open,FileAccess.ReadWrite);

IWorkbook workbook = application.Workbooks.Open(inputStream,ExcelOpenType.Automatic);
IWorksheet worksheet = workbook.Worksheets[0];

// Other code here...

worksheet.InsertRow(nextRow);

// Expect the Worksheet_Change code to run when the lines below are executed
worksheet.Range[nextRow,2].Value2="US";
worksheet.Range[nextRow,3].Value2= state;
worksheet.Range[nextRow,4].Value2= territory;
worksheet.Range[nextRow,5].Value2= practiceCode;
worksheet.Range[nextRow,6].Value2= foundRow.Cells[5].Value;
worksheet.Range[nextRow,7].Value2= foundRow.Cells[6].Value;

I tried setting the .Value, .Text and .Value2 but none of them seem to make the Worksheet_Change event fire.

I have also confirmed that the macro is there. I save the document to a new Excel spreadsheet and when I open this new document the new rows exist but they are not blue. If I change a value at that time the color changes to blue.


1 Reply

RS Ramya Sivakumar Syncfusion Team May 25, 2022 08:37 AM UTC

Hi Gene,


Greetings from Syncfusion.


Unfortunately, XlsIO has no support for Macro Execution. And, we don’t have any plans to implement this feature. But, XlsIO preserves macro content and allows to edit or create macro content as mentioned in the UG documentation.

Regards,

Ramya.


Loader.
Up arrow icon