Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Difference between Excel.WorkbookEvents_SheetChangeEventHandler and Excel.AppEvents_SheetChangeEventHandler
Hi i want to what is the difference between
Excel.WorkbookEvents_SheetChangeEventHandler and Excel.AppEvents_SheetChangeEventHandler. i want to fire an event When any cell changes its value because of an external link. But the event is getting fired only for the source workbook and not for the dependent workbook. Suppose i have 2 workbooks. Hello.xls and Fine.xls. Assume cell B1 in HelloSheet1 of Hello.xls gets its input from cell A2 of FineSheet3 in Fine.xls. When i change the value in Fine.xls , the value gets updated in Hello.xls. But the event gets fired only for Fine.xls and not for Hello.xls. I want to fire an event when value cell B1 in HelloSheet1 of Hello.xls is changed because of cell A2 of FineSheet3 in Fine.xls. This is what i am doing namespace ShtChangeEvnt { public class Form2 : System.Windows.Forms.Form { public Excel.ApplicationClass xlAppNew=null; private Excel.AppEvents_WorkbookOpenEventHandler EventDel_WorkbookOpen; private Excel.WorkbookEvents_SheetChangeEventHandler EventDel_WBSheetChange; private Excel.AppEvents_SheetChangeEventHandler EventDel_AppSheetChange; private Excel.Workbook xlBook; private Excel.Worksheet xlSheet ; public void AddHandler(string strFPath, int OpenFlag) { if(xlAppNew==null) xlAppNew=new Excel.ApplicationClass(); if(OpenFlag==1) { EventDel_WorkbookOpen= new Excel.AppEvents_WorkbookOpenEventHandler( WBopen); xlAppNew.WorkbookOpen += EventDel_WorkbookOpen; EventDel_AppSheetChange= new Excel.AppEvents_SheetChangeEventHandler ( AppSheetChange); xlAppNew.SheetChange += EventDel_AppSheetChange; xlAppNew.Visible=true; xlAppNew.UserControl=true; xlBook= xlAppNew.Workbooks.Open(strFPath,3,Missing.Value ,...); }// end if else { Excel.Workbook xlBook2=xlAppNew.Workbooks.Open(strFPath,3,Missing .Value ....); EventDel_WBSheetChange= new Excel.WorkbookEvents_SheetChangeEventHandler( WBSheetChange); xlBook2.SheetChange += EventDel_WBSheetChange; }// end else }// end AddHandler private void WBopen(Excel.Workbook Wb) { EventDel_WBSheetChange= new Excel.WorkbookEvents_SheetChangeEventHandler( WBSheetChange); xlAppNew.ActiveWorkbook.SheetChange += EventDel_WBSheetChange; }// end WBopen private void AppSheetChange(object Sh, Excel.Range Target) { logToFile("C:\\AppSheetChangeEvnt.txt","Hi tis is AppEvnt fired fr "+Target.Worksheet.Name.ToString()); }// end AppSheetChange private void WBSheetChange(object Sh, Excel.Range Target) { logToFile("C:\\WBSheetChangeEvnt.txt","Hi tis is WBEvnt fired fr "+Target.Worksheet.Name.ToString()); }// end WBSheetChange public static void logToFile(string strPath, string strData) { code to create/open txt file } } } When i change the value in Fine.xls , the value gets updated in Hello.xls. But both the events get fired only for Fine.xls and not for Hello.xls . the txt files contain Hi tis is AppEvnt fired fr FineSheet3 in AppSheetChangeEvnt.txt and Hi tis is WBEvnt fired fr FineSheet3 in WBSheetChangeEvnt.txt I want to capture the SheetChange occuring in Hello.xls because of Fine.xls. Please someone guide me in this regard and let me if i am going wrong anywhere. With Regards Daffo |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Averaging Time Difference | Excel Discussion (Misc queries) | |||
Formula to find the working days difference between to dates? | Excel Discussion (Misc queries) | |||
Time difference | Excel Worksheet Functions | |||
Difference between two months | Excel Worksheet Functions | |||
charting a difference of 2 columns' w/o adding a difference column | Charts and Charting in Excel |