Sample on Excel Events

Add-in Express™ Support Service
That's what is more important than anything else

Sample on Excel Events
Creating Excel 2010, 2007 addin. Customizing Excel Ribbon: C#, VB.NET 
Leon Lai Kan




Posts: 200
Joined: 2018-12-20
Hi,

I am playing with this sample:

Creating Excel 2010, 2007 addin. Customizing Excel Ribbon: C#, VB.NET
https://www.add-in-express.com/creating-addins-blog/2012/05/29/write-addins-excel2010/

I want to see the addin in action.

SheetSelectionChange:
This works fine: I select a range, and cell A1 displays "8 cells selected"


SheetActivate:
This also works fine: I click Sheet 2, and cell A1 displays " You've activated Sheet: Sheet 2"


SheetChange:
I cannot see the event in action. I change a few data on sheet 1, but I don't see anything happen.
I suppose the message is written in Console.

How can I see the message displayed by the event handler?

----------------------------------------------------------------------------
I also tried another experiment:

I tried to make the message appear in cell A1 (like the preceding Subs) as foll:
But program crashes (on the line indicated).
Where is the problem?

private void adxExcelEvents_SheetChange(object sender, object sheet, object range)
        {
            Excel.Worksheet worksheet = null;
            Excel.Range rng = null;
            Excel.Range cells = null;
            Excel.Range feedbackrange = null;    // added
            try
            {
                worksheet = (Excel.Worksheet)sheet;
                rng = (Excel.Range)range;

                cells = rng.Cells;
                worksheet = (Excel.Worksheet)sheet;       //added
                feedbackrange = worksheet.get_Range("A1", "A1");    // added



               feedbackrange.Value = (String.Format("{0} cells changed. In worksheet {1}", cells.Count, worksheet.Name));    //added  --- ERROR IS ON THIS LINE ????????

               
                //Console.WriteLine(String.Format("{0} cells changed. In worksheet {1}", cells.Count, worksheet.Name));    // disabled
            }
            finally
            {
                if (cells != null)
                    Marshal.ReleaseComObject(cells);
            }



Thanks
Leon
Posted 11 Jan, 2019 05:02:53 Top
Andrei Smolin


Add-in Express team


Posts: 16588
Joined: 2006-05-11
Hello Leon,

Leon Lai Kan writes:
I tried to make the message appear in cell A1


Use System.Diagnostics.Debug.WriteLine() to post a debug message; start the DebugView utility (http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx) to get the debug message.

Now you change a cell in an event that occurs when a cell is being changed; I assume this may create an endless loop and end with StackOverflow or such.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 11 Jan, 2019 06:07:37 Top
Leon Lai Kan




Posts: 200
Joined: 2018-12-20
Hi, Andrei

I assume this may create an endless loop and end with StackOverflow or such.


Yes, this is indeed the error message I get!

This may be the reason why the ADX sample does not display the message in cell A1, as in the 2 preceding examples?


Best Regards,
Leon
Posted 11 Jan, 2019 06:15:09 Top
Leon Lai Kan




Posts: 200
Joined: 2018-12-20
Andrei,

I can type only that far:
using System.Diagnostics

IntelliSense does not recognize .Debug

Leon
Posted 11 Jan, 2019 06:37:13 Top
Andrei Smolin


Add-in Express team


Posts: 16588
Joined: 2006-05-11
Leon,

If I remember correctly there's no "using" keyword in VB.NET. You should write this code line:

System.Diagnostics.Debug.WriteLine({a message string here})

See e.g. https://www.add-in-express.com/forum/read.php?FID=10&TID=13499.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 11 Jan, 2019 07:44:39 Top
Leon Lai Kan




Posts: 200
Joined: 2018-12-20
Hi, Andrei

Thanks

Leon
Posted 14 Jan, 2019 06:11:35 Top
Andrei Smolin


Add-in Express team


Posts: 16588
Joined: 2006-05-11
Welcome!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 14 Jan, 2019 06:33:49 Top