LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default SheetChange event crashes using Range.set_value (C#)

When I get a SheetChange event that contains a cell using my custom function
I cannot modify the value of any cells in the target range.
range is the target range passed into the sheet change event
gid_col is the column I wish to validate


for(int a = 1; a <= range.Areas.Count; a++)
{
Excel.Range area = range.Areas[a];
for(int r = 0; r < area.Rows.Count; r++)
{
//Excel.Range cell = (Excel.Range)area.Cells[r,1];
int row = area.Row + r;
if((row_changes[row].Equals(3))
&&(area.Column <= gid_col)
&&(area.Column+area.Columns.Countgid_col))
{
Excel.Range cell =
(Excel.Range)area.Cells[r+1,gid_col+1-area.Column];
String f = (String)cell.Formula;
try {
cell.set_Value(Excel.XlRangeValueDataType.xlRangeV alueDefault, "wtf"); }
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Sheet change
error\n" + ex.ToString(),"Localization Addin");
}
}
}
area = null;
}


the code works fine if no cell in the target range uses my custom function,
but blows up with this error otherwise...

System.Runtime.InteropServices.COMException(0x800A 03EC): Exception from
HRESULT 0x800A03EC.
at System.RuntimeTYpe.ForwardCallToInvokeMember(Strin g memberName, ...)
at Microsoft.Office.Interop.Excel.Range.set_Value(Obj ect
RangeValueDataType, Object)


also if I try to change other cell properties, like Font.Italic it has no
effect if my custom function is used by any cell in the target

This is the code for my custom function
using System;
using System.Windows;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Microsoft.Win32;

namespace LocalizationFunctions
{
using Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;

/// <summary
/// Summary description for Class1.
/// </summary
//[GuidAttribute("EE98CECC-2DEF-4d0b-B707-1985711163F5"),
ProgId("LocalizationFunctions.Functions")]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Functions
{
public Functions()
{
//
// TODO: Add constructor logic here
//
}
public String TAG(Excel.Range range)
{
String result = "";
try
{
for(int a = 1; a <= range.Areas.Count; a++)
{
Excel.Range area = range.Areas[a];
for(int r = 1; r <= area.Rows.Count; r++)
{
for(int c = 1; c <= area.Columns.Count; c++)
{
Excel.Range _cell = (Excel.Range)area.Cells[r,c];

if(_cell.Value2 != null)
{
String val = _cell.Value2.ToString();
if(val.Length0)
{
if(result.Length0)
{
result += "_";
}
result += val;
}
}
//_cell = null;
}
}
//area = null;
}
result = result.Replace(' ','_');
result = result.Replace('\n','_');
result = result.Replace('\t','_');
//result = (String)range.Value2;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Bugger2!\n"
+ex.ToString(),"Localization Function");

result = "ERROR!";
}

return result;
}

[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type type)
{
Registry.ClassesRoot.CreateSubKey(GetSubKeyName(ty pe));
Registry.ClassesRoot.CreateSubKey("CLSID\\{" +
type.GUID.ToString().ToUpper() + "}\\Programmable");
RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(
"CLSID\\{" + type.GUID.ToString().ToUpper() +
"}\\InprocServer32");
key.SetValue("",
System.Environment.GetFolderPath(Environment.Speci alFolder.System)
");
}

[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type type)
{
Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(ty pe),false);
}

private static string GetSubKeyName(Type type)
{
string s = @"CLSID\{" + type.GUID.ToString().ToUpper() +
@"}\Programmable";
return s;
}

}
}

Any ideas?
 
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
SheetChange event restore old value Anton Sommer Excel Programming 1 August 8th 05 10:36 PM
How to know what caused SheetChange event.. Srini Excel Programming 0 April 26th 05 11:22 PM
how to handle 'sheetchange' event on 'add-in' Takoyaki Excel Programming 2 December 19th 04 04:50 AM
SheetChange Event Tom Ogilvy Excel Programming 0 November 23rd 04 07:10 PM
SheetChange Event crispbd[_34_] Excel Programming 0 November 23rd 04 06:43 PM


All times are GMT +1. The time now is 11:44 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"