Automate Excel UserForm through VBE from c#

V

Vidster

I'm trying to gain information about an excel userform using VBA
extensibility from c#.

When I cast the designer object as a userform, then try to count the
contorls on the userform :

Form.UserForm myForm = (Form.UserForm)mycom.Designer;
string myNum = (myForm.Controls.Count).ToString();

I get errormessage:

{"The server threw an exception. (Exception from HRESULT: 0x80010105
(RPC_E_SERVERFAULT))"}

Any idea how I can get around this?
 
C

Cindy M.

Hi Vidster,
When I cast the designer object as a userform, then try to count the
contorls on the userform :

Form.UserForm myForm = (Form.UserForm)mycom.Designer;
string myNum = (myForm.Controls.Count).ToString();

I get errormessage:

{"The server threw an exception. (Exception from HRESULT: 0x80010105
(RPC_E_SERVERFAULT))"}

Any idea how I can get around this?

Sometimes, when I get this kind of thing from a PIA that probably
hasn't been "tweaked" a lot, it helps to do this (whereby I haven't
checked the namespace for Controls, it's just a guess):

Form.Controls ctls = myForm.Controls;
int nrCtls = ctls.Count;
string myNum = nrCtls.ToString();

IOW, spell it out for C# and declare every little bit individually.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
V

Vidster

Cindy M. said:
Hi Vidster,


Sometimes, when I get this kind of thing from a PIA that probably
hasn't been "tweaked" a lot, it helps to do this (whereby I haven't
checked the namespace for Controls, it's just a guess):

Form.Controls ctls = myForm.Controls;
int nrCtls = ctls.Count;
string myNum = nrCtls.ToString();

IOW, spell it out for C# and declare every little bit individually.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)


This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)

I did try that but as soon as I hit the line :

Form.Controls ctls = myForm.Controls;

I get the error.

I think it must be because I'm casting the VBE designer object as a
userform. VB.NET seems to do it automatically, i can't figure out how to
replicate in c# :(
 
V

Vidster

Vidster said:
Form.Controls ctls = myForm.Controls;

I get the error.

I think it must be because I'm casting the VBE designer object as a
userform. VB.NET seems to do it automatically, i can't figure out how to
replicate in c# :(

It appears that when I cast the designer object to a userform in both c# and
VB.NET I get the above error. In VB.NET if I cast the designer object to
'Object', then the code works. If I return the type
(Microsoft.VisualBasic.Information.TypeName) of the designer object I cast to
'Object', it returns 'userform'. What's going on!!!!!
 
F

filip

I'm trying to gain information about an excel userform using VBA
extensibility from c#.

When I cast the designer object as a userform, then try to count the
contorls on the userform :

Form.UserForm myForm = (Form.UserForm)mycom.Designer;
string myNum = (myForm.Controls.Count).ToString();

I get errormessage:

{"The server threw an exception. (Exception from HRESULT: 0x80010105
(RPC_E_SERVERFAULT))"}

Any idea how I can get around this?

Hi,

you can try using GemBox.Spreadsheet. This component makes working
with Excel from .NET relatively easy.
http://www.gemboxsoftware.com/GBSpreadsheet.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top