problem after adding Macro

  • Thread starter abhijit_ghawate
  • Start date
A

abhijit_ghawate

Hi,

I am developing a excel addin using c#
on click of a command bar button create a worksheetsheet and add a macro to
the workbook the following way

Microsoft.Vbe.Interop.VBComponent module=null;

module = application.ActiveWorkbook.VBProject.VBComponents.Add(
Microsoft.Vbe.Interop.vbext_ComponentType.vbext_ct_StdModule);

module.Name = "Macro1";
module.CodeModule.AddFromString(macro_string);

i have also added a combo box to the work sheet whose OnAction property i
have set to the above added Macro - Macro1.

when the worksheet is created there is a cell which is selected and i try
typing something, but nothing types, it is as though no cell has been
selected and i am trying to type. Only in this case i actually have a cell
selected. (its wierd...its as if its hung)

Now i go ahead and click on the cell (reselect the cell by mouse) which was
selected and type again. This time it types. But now when i go and click on
the combo-box, the debug code window for the macro opens up and i see the
words i was trying to type before (and were not typed) in the macro code at
the bottom and so the macro actually had a problem executing.

i feel somehow after the macro was added using AddFromString thru C# code
the cursor was put in the Macro code window and after the addition it was
never returned to the excel workseet. Hence when i try to type it gets
written in the macro code window instead of the worksheet.

If anybody knows the problem plase help ...this is driving me crazy...

Thanks
Abhijit
 
C

Cindy M.

Hi =?Utf-8?B?YWJoaWppdF9naGF3YXRl?=,

I really don't have any experience with this, but since no one else has
responded, I figure I can share the two things I'd try in such a situation

1. The VB Editor has a "Designer mode". This is active if, for example, the
code is shown in a code window. As I recall, the VBE object model provides a
method to CLOSE "Designer windows". Open "Designer windows" are known to cause
obscure problems. So I'd try closing this particular one (closing them all
would be "rude" if the user works in the VB editor at all) and see if that
doesn't release the focus.

2. The other thing I'd try is explicitly activating a cell in the worksheet.
I am developing a excel addin using c#
on click of a command bar button create a worksheetsheet and add a macro to
the workbook the following way

Microsoft.Vbe.Interop.VBComponent module=null;

module = application.ActiveWorkbook.VBProject.VBComponents.Add(
Microsoft.Vbe.Interop.vbext_ComponentType.vbext_ct_StdModule);

module.Name = "Macro1";
module.CodeModule.AddFromString(macro_string);

i have also added a combo box to the work sheet whose OnAction property i
have set to the above added Macro - Macro1.

when the worksheet is created there is a cell which is selected and i try
typing something, but nothing types, it is as though no cell has been
selected and i am trying to type. Only in this case i actually have a cell
selected. (its wierd...its as if its hung)

Now i go ahead and click on the cell (reselect the cell by mouse) which was
selected and type again. This time it types. But now when i go and click on
the combo-box, the debug code window for the macro opens up and i see the
words i was trying to type before (and were not typed) in the macro code at
the bottom and so the macro actually had a problem executing.

i feel somehow after the macro was added using AddFromString thru C# code
the cursor was put in the Macro code window and after the addition it was
never returned to the excel workseet. Hence when i try to type it gets
written in the macro code window instead of the worksheet.

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 :)
 

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