My goal is to be able to have some C# code execute every 5 minutes from Excel. Between runs, i would like to have control in Excel so that I can perform normal tasks. This seems doable but my moniker is quite apt in this case.
The problem seems to be based around my inability to multithread in Excel (so my 'sleep' attempts failed), nor do can I execute "OfficeCodeBehind" functions from VBA/macros.
Any one have ideas on how to do this I'm about ready to build a mouse controlling external app to scroll over and hit my Excel buttons every five mintues... please save me from this embarassing solution.

Passing Control between Excel and C# code
KenCubs
Sorry for turning this into a blog, but i think the newbie has found a work around.
Although i can't get my external UberApp to run my assembly code by 'clicking' the OLEObject associated with the CommandButton, i can make it send 'save', 'open' and 'quit' commands to my excel application. And I know that the OfficeCodeBehind works when I open the excel sheet.... so maybe it will run the Assembly code for saving and quiting as well.
A few quick changes put in a beforeSave event handler in my Assembly (which really just runs the assembly functions associated with the command button i wanted to press) and i'm done. I just send a saveworkspace() command to Excel from my UberApp every five minutes.
Now if I can only get it to stop creating a thousand instances of excel from running in the background....
Brian Vallelunga
hmmm... no ideas for an easy solution. Does this mean i'm asking a dumb question or does no one actually know a work around
I've tried the following approach but did run into a problem at the end. I created a second application, let's call it UberApp, that creates an instance of excel and opens the workbook with OfficeCodeBehind. The C# code runs correctly when the Excel sheet opens. All i need at this point is to be able to 'click' a CommandButton from my UberApp, which I think will set off the OfficeCodeBehind code that is the event handler for the excel CommandButton.
So far, so good. UberApp is able to get the OLEObject associated with the Excel CommandButton (i can, for example, delete the button and such). So to 'click' the OLEObject i'm using the following bit of VB code
theexcelsheet.OLEObjects("CommandButton1").Verb()
When I run this, the button on the excel sheet does go thru the visual of getting clicked but no code runs (i've tried connecting regular macros to this button as well as the C# event handler). Why is this and how can i get around it I've tried different small changes such as sending different parameters to Verb().
I"m thinking it has something to do with threading and why I can't create forms from my OfficeCodeBehind code. Even pointing me in the right direction on that would help.
sorry for the newbie questions
yss
Why don't you just create a C#/Excel Addin component then you can do exactly what you want and have full control over Excel