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 |
|
Andrei Smolin
Add-in Express team
Posts: 18829
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.
Andrei Smolin
Add-in Express Team Leader |
|
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 |
|
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 |
|
Andrei Smolin
Add-in Express team
Posts: 18829
Joined: 2006-05-11
|
|
Leon Lai Kan
Posts: 200
Joined: 2018-12-20
|
|
Andrei Smolin
Add-in Express team
Posts: 18829
Joined: 2006-05-11
|
Welcome!
Andrei Smolin
Add-in Express Team Leader |
|