Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Udfs and eventhandler for excel in managed code

i have followed the following same approach as u suggested to create
automation add-in.
http://blogs.msdn.com/eric_carter/ar...01/273127.aspx
..
and created following code

using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Text;
using Microsoft.Office.Interop.Excel;

using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Diagnostics;


namespace lnzv2
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class wsf
{
Excel.DocEvents_ChangeEventHandler EventDel_CellsChange;

Excel.Application xlApp;
Excel.Workbook xlBook;
Excel.Worksheet xlSheet1, xlSheet2, xlSheet3;

public wsf()
{

myInitialization();

}

public void myInitialization()
{
xlApp = new Excel.Application();
xlBook = xlApp.Workbooks.Add(Missing.Value);
xlBook.Windows.get_Item(1).Caption = "XL Event Test";
xlSheet1 = (Excel.Worksheet)xlBook.Worksheets.get_Item(1);
xlSheet2 = (Excel.Worksheet)xlBook.Worksheets.get_Item(2);
xlSheet3 = (Excel.Worksheet)xlBook.Worksheets.get_Item(3);
xlSheet2.Activate();
EventDel_CellsChange = new Excel.DocEvents_ChangeEventHandler(
CellsChange);
xlSheet1.Change += EventDel_CellsChange; // ........question1

}

private void CellsChange(Excel.Range Target )
{
Target.Value2=10;;


}


public int NumberOfCells(object Range)
{



int [,] TheValues = new int[1, 1];
TheValues[0, 0] = 1;
TheValues[0, 1] = 2;
TheValues[1, 0] = 3;
TheValues[1, 1] = 4;


Excel.Range r = Range as Excel.Range;

r.set_Value(Missing.Value,TheValues);//......question2


return r.Cells.Count;
}
}
}


Given question1 I am unable to invoke the event.So please give me an
idea
how the event can be used and correct me if i am wrong.
In question2 I am unable to get the value in the cells of the given
range
passes in the function and it gives an error in the cell where i have
written
the UDF =NumberOfCells(b2:c3).

Please give a helping hand.
thanks.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
BackgroundWorker in Excel 2007 Managed Add-In Chris Herring Excel Programming 1 October 26th 06 10:32 AM
Excel v10 can't find function in C# .Net managed Automation add-in Andrew Excel Programming 2 May 27th 06 07:39 AM
Does MS Office 2002 have support for managed code extensions? Mircea Pleteriu Excel Programming 1 February 14th 05 08:17 AM
refedit control in 2003 and managed code add-in? Nick Hodge Excel Programming 2 September 7th 04 03:16 PM
.Net Managed Code - Excel Francois[_3_] Excel Programming 0 August 12th 04 07:37 AM


All times are GMT +1. The time now is 10:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"