View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
[email protected] korav@inbox.ru is offline
external usenet poster
 
Posts: 3
Default Toggle Design Mode in Excel by AddIn

On 28 ÎÏÑÂ, 03:46, "Chip Pearson" wrote:
It is very simple in VBA. The following procs will turn design mode on or
off.


Thanks a lot for your participation!

Yes, we've seen the similar solution in C++


//Application.CommandBars.FindControl(ID:=1605).Exec ute

_variant_t vtOptional(DISP_E_PARAMNOTFOUND, VT_ERROR);

_CommandBars oBars(oApp.GetCommandBars());

CommandBarControl oCtrl(

oBars.FindControl(

vtOptional,

_variant_t(1605L),

vtOptional,

vtOptional));

if (oCtrl)

{

oCtrl.Execute();

}

It isn't real good, IMHO. There are two caveats at least, I think.

The first caveat is connected to "magic numbers" i.e. button's ID.
Did anybody from M$ promise to keep it unchanged forever? ;)

The second one is about ideology of emulation of button click. If we
use it from the macro, which was built in particular workbook, it
works in properly way. But our AddIn could be used without any
relation to the active now workbook (yes, in our example we used the
active workbook, but it was done only for clarification of code).


And one more question for you about Design Mode detection. I
understand, it`s meaningless question for VBA, but, for our case it is
possible.
So, in our AddIn we want to control state of particular workbook - is
it in Design Mode? We've written this code:

Excel::_WorkbookPtr wb_ptr;
......

VBIDE::_VBProjectPtr ptrVBProj;
// ptrVBProj = wb_ptr-GetVBProject();
hr = wb_ptr-get_VBProject(&ptrVBProj);

if(SUCCEEDED(hr))
{
VBIDE::vbext_VBAMode mode;
hr = ptrVBProj-get_Mode(&mode);
if(SUCCEEDED(hr))
{
switch(mode)
{
case VBIDE::vbext_vm_Run:
MessageBox(NULL, "IDE in Run mode", "My Addin", MB_SETFOREGROUND);
break;
case VBIDE::vbext_vm_Break:
MessageBox(NULL, "IDE in Break mode", "My Addin",
MB_SETFOREGROUND);
break;
case VBIDE::vbext_vm_Design:
MessageBox(NULL, "IDE in Design mode", "My Addin",
MB_SETFOREGROUND);
break;
}
}

}
else
{
MessageBox(NULL, "Please Enable \"Trust access to Visual Basic
Project\" option\n under Tools\\Macro\\Security menu.", "My Addin",
MB_SETFOREGROUND);
}


It works, but it always returns VBIDE::vbext_vm_Design without any
relation to the REAL state of the Workbook. :(